Spring can parse @Configuration classes using ClassReaders
Assuming that we have the following scenario
We have an autoconfiguration class with multiple @Bean definitions
One of the @Bean has all conditions passed while second @Bean have @ConditionalOnClass & the class is not present in the class path
@Configuration
class CustomConfiguration {
@Bean
@ConditionalOnClass(String.class)
String knownClass() {
return "Hello";
}
@Bean
@ConditionalOnClass(MissingClass.class)
MissingClass secondBean() {
return new MissingClass();
}
}
In this scenario, I have couple of questions
- Does Spring Boot AutoConfiguration register the first bean into the
ApplicationContext? - If (1) is true, will my breakpoint inside first
@Beanmethod be hit during debug - If (2) is true, how is the
*AutoConfigurationclass get loaded into JVM as this class will refers to other classes (from second @Bean) which cant be resolved at class load time - If (2) is false, does spring generate a class at runtime with just the first
@Beanmethod and invoke the method?
Thanks