I am trying to write a service using Spring 5, however I receive a Dependency Injection issue. I'm having problems using @Resource.I have recently migrated from Spring 4 to Spring 5.0.5 and have the following jars in the classapath
Since you are defining your context configuration for your class as TestClass.OptionalConfiguration then this is the only configuration your tests know about. If you want to define CiScheduledExecutor as a bean in this context as well then you need to component scan for it in your test configuration:
@Configuration
@ComponentScan("my.base.package")
static class OptionalConfiguration {
@Bean
List<Item> someString() {
return new ArrayList<>();
}
@Bean
Object foo(List<Item> obj) {
return new Object();
}
}
Although if you are doing integration like tests that require pulling in several bean definitions from your actual runtime Spring context then you should consider using @SpringBootTest which does a lot of the work for you, see here:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.