I need to delay my application "service" bean processing after all Spring Boot cloud auto-configuration is finished.
"service" bean has dependency both on SQL DataSource and other Bean (S3 repository) which is optional and can be created based on cloud services configuration or directly configured properties (or even not created at all). Both underlying S3 and SQL services are configured perfectly based on various external conditions. They behave well with direct, inderect properties, cloud and so on.
So now I have something like...
@Autowired(required=false)
S3Storage s3;
@Autowired
SQLDatabase db;
@Bean
MyService myservice() {
if (s3 != null) {
return new SQLWithS3Implementation(db, s3);
} else {
return new SQLImplementation(db);
}
}
What have I do with this Bean so it is not processed before cloud services (spring-cloud-connectors is used) with s3 yet null?
I need something like...
@ProcessAfter(CloudAutoConfiguration.class)
But how actually to do so in Spring Boot / Spring Cloud?
In Spring boot, you can make use of @ConditionalOnBean Doc : http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnBean.html
@ConditionalOnBean(CloudAutoConfiguration.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With