We have multiple application contexts in our application and use them in a hierarchical order:
new SpringApplicationBuilder( HierarchicalApplication.class )
.logStartupInfo( false )
.bannerMode( Mode.OFF )
.child( ChildContext1.class )
.logStartupInfo( false )
.bannerMode( Mode.OFF )
.sibling( ChildContext2.class )
.logStartupInfo( false )
.bannerMode( Mode.OFF )
.run( args );
Each of the child contexts has an own application.properties file, which is used to configure the corresponding context. However, we need to configure them individually via system properties. For instance: Both ChildContext1 and ChildContext2 would have own datasources with different usernames. Usually one could just use spring.datasource.username, but setting this as system property would override the property for both contexts. So instead we need properties like child1.spring.datasource.username and child2.spring.datasource.username. Obvsiously we could just duplicate them explicitly in the child's properties files:
child1.spring.datasource.username=postgres
spring.datasource.username=${child1.spring.datasource.username}
However, this would mean we would need to write a lot of boilerplate properties.
Our idea was to provide a certain property (modulename or prefix) in both contexts which would define a fixed prefix for the properties. We though then about using some kind of EnvironmentPostProcessor, but the post processor cannot see this property modulename. ApplicationListeners doesn't seem to be called early enough and we are not sure if we can solve our issue with a PropertySource.
Any ideas?