Spring can parse @Configuration
classes using ClassReader
s
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
@Bean
method be hit during debug - If (2) is true, how is the
*AutoConfiguration
class 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
@Bean
method and invoke the method?
Thanks