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

Change of behavior in property loading order #26999

Closed
chengchen opened this issue Jun 21, 2021 · 3 comments
Closed

Change of behavior in property loading order #26999

chengchen opened this issue Jun 21, 2021 · 3 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@chengchen
Copy link

chengchen commented Jun 21, 2021

Hello,

I was trying to upgrade our applications from 2.4.6 to 2.5.1 and noticed a change of behavior in property loading order. And after further testing, this change of behavior is happening in both 2.4.7 and 2.5.1, so it has to be a quite recent commit.

Personally, I am not sure about the correct behavior anymore (even after reading your documentation :) ... What is bothering us is this is breaking many applications on our side and it would be nice to at least know the future direction of designing the configuration hierarchy, so that we don't have so much pain each time we upgrade... Hope you could understand our concern.

I have provided an example here: https://github.com/chengchen/spring-boot-properties-loading-debug

After building and starting the app:

$ mvn clean install
$ cd app && mvn spring-boot:run

We execute this:

$ curl localhost:8080/bar

If using 2.4.6, the output is app-default.
If using 2.5.1 or 2.4.7, the output is common.

The reason we do like this is to reuse some common modules between several applications, but still allow to override some module default values. Of course, we could override in more specific profiles like application-prod.yml but we try to avoid repeating in other environment like application-staging.yml when this value is somehow application default.

Many thanks for your help!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 21, 2021
@philwebb
Copy link
Member

I suspect this is a duplicate of #26960. I'll check your sample once I've committed a fix.

@philwebb philwebb self-assigned this Jun 21, 2021
@philwebb
Copy link
Member

I was wrong, this is not a duplicate of #26960, you're actually hitting the fix for #26593. I'm afraid that one is a legitimate bug in my opinion and we should be loading all regular files before all profile-specific file (regardless of if they are under /config or not).

We have an open issue (#24688) to look at improving your scenario since it seems to come up a lot. For now, I would recommend that you use an EnvironmentPostProcessor in your common lib to add a property source containing the common properties. You can register it in META-INF/spring.factories and it will be picked up automatically. Take a look at #27000 which has some sample code that shows the basic approach.

@philwebb philwebb added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 22, 2021
@chengchen
Copy link
Author

Hi @philwebb

Thank you for your investigation! I did come across that ticket yesterday but as I said I was not sure about the correct behavior :) So, you are basically indicating that the current 2.5.1 should hold the expected/correct behavior. I will try to adapt our config to it then...

I will probably not use a EnvironmentPostProcessor which is too much coupling to Spring stuff... and adds unnecessary complications. Thanks anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants