I have been breaking my head in getting Spring @Autowired
to work inside maven tests. When I run the JUnit tests inside IntellJ (did not try Eclipse) it works. But when I run mvn clean install, the JUnit tests fail with the following error
testApp(com.sample.spring.AppTest): Error creating bean with name 'com.sample.spring.AppTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.sample.spring.AppB com.sample.spring.AppTest.appB; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.sample.spring.AppB] 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)}
I have created a self contained sample project that exhibits this behaviour consistently. I am using Spring 3.1.1. I am sure someone faced the same issue and cracked it. Looking for some pointers regarding this issue.