I use spring 5.2.8 and I have three annotation configs:
@Configuration
@ComponentScan(basePackageClasses = {
Foo.class
})
public class AConfig {
@Bean
public Something something() {..}
}
@Configuration
@ComponentScan(basePackageClasses = {
Bar.class
})
public class BConfig {}
@Configuration
@Import({ AConfig.class, BConfig.class })
public class MainConfig {}
This is the way I start my spring context:
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
The problem with such configuration is that spring doesn't see/initialize/scan beans in the packages of base package classes. In log I see only
[TRACE] org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean
Is this a bug or expected behavior?
Comment From: snicoll
AFAIK, this should work. Can you move that code snippet in a project that we can run ourselves?
You can share it with us by attaching a zip to this issue or sharing a link to a GitHub repository.
Comment From: PavelTurk
The problem was that I had to set classLoader for AnnotationConfigApplicationContex
manually as PathMatchingResourcePatternResolver
didn't find my config classes.