I have a simple Spring Boot Application structure as follows
src/main/java com +- example +- myproject +- Application.java | +- config | +- SpringConfig.java | +- service | +- DBService.java src/main/test com +- example +- myproject +- config | +- MyTestRoot.java src/test/resources applicationContext-test.xml Application.java is annotated with
@SpringBootApplication @EnableJms @ComponentScan @EnableTransactionManagement @EnableAutoConfiguration SpringConfig.java is annotated with @Configuration and has a method which returns a new instance of DBService. The method is annotated with @Bean
@Bean public DBService dbService() { return new DBService(); } The DBService class has repositories Autowired into it. These repositories are from another project dependency and provide connection to RDBMS/Data Store.
I defined a bean in applicationContext-test.xml
<bean id="dbService" class="com.path.to.class.in.dependency"/> When I autowire the dbService in my test class, I get an error "Error creating bean with name 'dbServices': Injection of autowired dependencies failed;"
What I am doing wrong here? I am using spring boot 1.3.5 and cannot use the @SpringBootTest annotation since it available from 1.4 onwards. Any help will be much appreciated.
EDIT: Since the DbService class in turn refers to repository classes (userRepositoty, customerRepository and so on), I tried to define the beans for those repositories too in the test context file. However, the repositories that I am injecting in the DbService class (in Main) are interfaces and the Spring Boot framework automatically resolves the actual implementations for me during runtime. I am not sure on how to do this in the test context.
codeError creating bean with name 'dbServices': Injection of autowired dependencies failedcode