Reputation: 66
I have a requirement to fetch stable set of properties from Spring cloud config server. Example : I have configured multiple like spring.profiles.active=jdbc,git. So, as per the priority the cloud config server fetches properties from JDBC i.e, from properties table and later it will fetches from git repository. The org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository#findOne(java.lang.String, java.lang.String, java.lang.String, boolean) method is consolidating in to a Environment object containing List propertySources. In this case the list is multiple PropertySource objects. Problem statement: I have a property called app.scheduler.timeout=9000 in properties table(JDBC backend) and the same property is also present in the git -profile.properties file as app.scheduler.timeout=9001. If you see the final Environment object, it will have the properties in both the PropertySources. I know that the merging will be done at the Cloud Config Client Side by preparing the bootstrap property source.
Is there any way we can prepare or get only stable set of propertySource from the Spring Cloud Config Server itself? i.e, single propertySource object in the List.
Note: In the above example I have mentioned only one property but I want this merging should happen for all the properties in response sent to the cloud config client.
Upvotes: 0
Views: 1272
Reputation: 66
Thank you @ryanjbaxter for providing the solution. CustomCompositeEnvironmentRepository should extend ComponsiteEnvironmentRepository.
Then in your configuration class add @AutoConfigureBefore(EnvironmentRepositoryConfiguration.class)
.
And you bean should be defined as follows
@Bean
@Primary
@ConditionalOnMissingBean(SearchPathLocator.class)
public CompositeEnvironmentRepository customCompositeEnvironmentRepository() {
return new CustomCompositeEnvironmentRepository(this.environmentRepos, properties.isFailOnCompositeError());
}
the complete solution is available in the below GitHub location: link
Upvotes: 2