Skip to content

localProperties get more preference over environmentProperties in spring boot 2.x #13738

@vtiwari2134

Description

@vtiwari2134

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:

  1. Create a cloud config server having some property let say spring.sample-property=sample property server
  2. Now create a local properties file local-config.properties having same property spring.sample-property=sample property client and load it through PropertySourcesPlaceholderConfigurer.
  3. Intialize POJO class through @ConfigurationProperties
  4. 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.

  1. 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
  1. Run config-server it will contains the cloud config property with property
    spring.sample-property=sample property server

  2. Run configClient-1.5.14.RELEASE it contains local property file(local-config.properties) with property
    spring.sample-property=sample property client

  3. 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});
  }

propertiesIssue.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions