I have Three configuration @Configuration
files , e.g. CrrConfig
, (CrrWsConfig
extends ParentCrrWsConfig
) ParentCrrWsconfig
has
@Configurtion
public class CrrWsConfig extends ParentCrrWsConfig {
....../// other configuration
}
@Configuration
public class ParentCrrWsConfig {
@Bean
@ConditionalOnBean
@DependsOn(value = { "enableQuartz" })
public SchedulerFactoryBean quartzScheduler(ApplicationContext applicationContext) {
.. do something
}
}
@Configuration
public class CrrConfig {
@Value("${enable.quartz}")
private String enableQuartzFlag;
@Bean
publiv String enableQuartz(){
return enableQuartzFlag;
}
}
if I define the bean enableQuartz
in a different class CrrConfig
, the ParentCrrWsConfig
class when configuring the application and instantiating all the Spring beans does not instantiate the quartzScheduler method, but it works if I declare the enabelQuartz been in the child classes CrrWsConfig
, Does the Default : org.springframework.boot.autoconfigure.condition.SearchStrategy.ALL
this really works or I have wrong understanding of the Search,.
Comment From: philwebb
@SanjayGautam I'm afraid you can't use @ConditionalOnBean
on regular @Configuration
classes, it's specifically designed for auto-configuration. See this part of the Javadoc.