-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
Hi,
In spring boot 2.x i think localProperties loaded through PropertySourcesPlaceholderConfigurer
are getting more preference over cloud config server properties with localOverride
flag as false(by default).
Working fine in spring boot version 1.5.x.
To reproduce the issue:
- Create a cloud config server having some property let say
spring.sample-property=sample property server
- Now create a local properties file
local-config.properties
having same propertyspring.sample-property=sample property client
and load it throughPropertySourcesPlaceholderConfigurer
. - Intialize POJO class through
@ConfigurationProperties
- It will load value as "sample property client" from local properties file rather than from cloud config server.
I am attaching a sample project that will demonstrate the above steps.
- Zip file contains 3 projects -
- config-server which contains cloud config server
- configClient-1.5.14.RELEASE which contains spring boot application with version 1.5.14.RELEASE
- configClient-2.0.3.RELEASE which contains spring boot application with version 1.5.14.RELEASE
-
Run config-server it will contains the cloud config property with property
spring.sample-property=sample property server
-
Run configClient-1.5.14.RELEASE it contains local property file(local-config.properties) with property
spring.sample-property=sample property client
-
Run configClient-2.0.3.RELEASE it contains local property file(local-config.properties) with property
spring.sample-property=sample property client
Now after running the clients these are the value that is bind to SpringProperty POJO class -
For configClient-1.5.14.RELEASE - sampleProperty = sample property server
(Correct behaviour)
For configClient-2.0.3.RELEASE - sampleProperty = sample property client
Output could be checked in log file(search for sample-property ------) or could be accessed through rest controller.
I triaged the issue and could see that in PropertySourcesDeducer
following snippet where there is filtering on enviromentProperties. Hence localProperties take more preference over enviromentProperties whether localOverride flag is true or not.
private PropertySources merge(PropertySources environmentPropertySources, PropertySources appliedPropertySources) {
FilteredPropertySources filtered = new FilteredPropertySources(appliedPropertySources, new String[]{"environmentProperties"});
return new CompositePropertySources(new PropertySources[]{filtered, environmentPropertySources});
}