I would like to enable custom setup and reasonable defaults with @ConditionalOnMissingBean? I have a spring boot application:
@Configuration
@Import({CustomConfiguration.class, DefaultConfiguration.class})
@EnableAutoConfiguration(exclude={MetricFilterAutoConfiguration.class})
public class Application {
@Autowired
ErrorListener errorListener;
}
and a CustomConfiguration, which allow either spring xml or component scanning:
@Configuration("customConfiguration")
@ImportResource("classpath:customContext.xml")
@ComponentScan({"org.custom.impl"})
public class CustomConfiguration
DefaultConfigurationuses ConditionalOnMissingBean:
@Bean
@ConditionalOnMissingBean
ErrorListener errorListener() {
return new LoggingErrorListener();
}
What I'm trying to achieve allows you to specify custom ErrorListeneron the classpath, if not defined then use the default value LoggingErrorListener(via ConditionalOnMissingBean). I found that it is DefaultConfigurationalways used before CustomConfiguration.
I experimented with @DependsOnand @Order, but without joy.