I have:
- module
app-core
- module
reporting-api
- multiple moduiles such as
reporting-elastic
,reporting-kafka
and so on.
app-core
has dependency to reporting-api
and also to reporting implementations
reporting implementations have dependency to reporting-api
Now in the app-core
there is property myApp.reporting = ELASTIC | NoOP | KAFKA
, here user select what implementation of reporting service should be created.
In each of the report implementation modules, i create the bean, so for example for elastic i have config:
@Configuration@ConditionalOnProperty(value = "myApp.reporting", havingValue = "ELASTIC")public class Configuration { @Bean ReportService elasticReportSertice(){ return new ElasticReportService(); }}
in reporting-kafka
i have:
@Configuration@ConditionalOnProperty(value = "myApp.reporting", havingValue = "KAFKA")public class Configuration { @Bean ReportService kafkReportService(){ return new KafkaReportService(); }}
And so on, now however when NoOP
is specified ( or NO property is specified at all) i want to create NoOp
version of the reporting service.
Currently, i do that in configuration in app-core
@Configuration@ConditionalOnProperty(value = "myApp.reporting", havingValue = "NoOp", matchIfMissing = true)public class AppCoreConfiguration { @Bean ReportService noOpService(){ return new NoOpReportService(); }}
This works, however having the bean definitions shattered across multiple config files seems pretty chaotic, is there some better pattern or more correct way how to achieve this?
Thanks for help!