I am facing a small challenge on which i do not know how to tackle it. In my current application we are using RabbitMQ as an AMQP broker (using spring-rabbit) and we successfully have written integration-tests where the RabbitMQ ConnectionFactory gets autowired etc.
Now we also have some Unit Tests for a small controller which give me an error when I run them using the command-line
grails test-app
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitMQConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.amqp.rabbit.connection.ConnectionFactory rabbitmq.config.RabbitMQConfig.connectionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.amqp.rabbit.connection.ConnectionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
When i run the Unit Test inside IntelliJ all works fine!
So i am wondering what the difference is between running the tests inside IntelliJ and the Grails command line. I guess it has something todo with the Environments that Grails runs the test in. But we also have wired up a RabbitMQTestConfig so the integration tests work with the test configuration.
I am a bit puzzled on why this works inside IntelliJ and not on the command-line. Any clue?