Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vtiwari2134 opened this issue Jul 10, 2018 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@vtiwari2134
Copy link

vtiwari2134 commented Jul 10, 2018

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 10, 2018
@vtiwari2134 vtiwari2134 changed the title localProperties are getting more preference over environmentProperties in spring boot 2.x localProperties get more preference over environmentProperties in spring boot 2.x Jul 10, 2018
@mbhave
Copy link
Contributor

mbhave commented Jul 10, 2018

Yup this looks like a bug with the PropertySourcesDeducer to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants