Skip to content

Clarifying change in config file ordering particularly with respect to spring.config.location and profile-specific files #25058

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

Open
barryspearce opened this issue Jan 30, 2021 · 4 comments
Labels
type: wiki-documentation A documentation update required on the wiki

Comments

@barryspearce
Copy link

I have a gradle build using multiple profiles to provide configuration overrides for different environments (live + dev).

app-base.properties is located inside the war
app-dev.properties is located outside the war in the top directory of the build so gradle bootRun will run with app-dev.properties overriding app-base.properties.

logging.file.name in app-base.properties is set to the live deployment logging directory.
logging.file..name in app-dev.properties is set to ./app.log

This setup has worked for the last 12 months, the gradle configuration that works is:

plugins
{
    id 'com.github.ben-manes.versions' version '0.36.0'
    id 'org.springframework.boot' version '2.3.8.RELEASE'
}
...
bootRun
{
  args = ["--spring.config.name=app", "--spring.config.location=file:./,classpath:/config/", "--spring.profiles.active=base,dev" ]
}

An upgrade to 2.4.2 with the following plugins, breaks the execution.

plugins
{
    id 'com.github.ben-manes.versions' version '0.36.0'
    id 'org.springframework.boot' version '2.4.2'
}

Here the logging.file.name set in app-dev.properties is ignored. The app-base.properties is used instead. To resolve I have had to downgrade back to 2.3.8.RELEASE.

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

Have you seen the section in the release notes and the migration guide to which it links? If not, please take a look and let us know if it helps.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jan 30, 2021
@barryspearce
Copy link
Author

barryspearce commented Jan 30, 2021

Thanks for that - not immediately obvious, although I have sorted it.

So the guide says:

With Spring Boot 2.3 and earlier, the order that the individual documents were added was based on profile activation order.

This is the key. I have been using profiles of base,dev with a spring.config.location=file:./,classpath:/config/. Of course this meant my external file did override the internal due to profile activation order. In 2.4 the location order now takes precedence and it is then fairly obvious that I specify the local directory first. So simple fix to reverse the ordering on spring.config.location.

No bug - although maybe worth an extra note in the migration guide because the behaviour of spring.config.location in combination with the profiles is not mentioned.

Thanks for your help!

@wilkinsona wilkinsona added type: wiki-documentation A documentation update required on the wiki and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jan 30, 2021
@wilkinsona wilkinsona reopened this Jan 30, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Jan 30, 2021

maybe worth an extra note in the migration guide because the behaviour of spring.config.location in combination with the profiles is not mentioned

That sounds like a good idea to me. Thanks for the suggestion. The section you've referenced is specifically about multi-document YAML files which you weren't using so there's definitely some room for improvement.

I've re-opened this issue as a reminder to update the guide.

@wilkinsona
Copy link
Member

We should probably reword "As of Spring Boot 2.4, external file always override packaged files (profile-specific or not)". The "always" only applies when using the default locations. If they're overridden and their ordering is changed, the "always" no longer holds true.

@wilkinsona wilkinsona changed the title logging.file.name not correctly set when multiple profiles are present (works in 2.3.8 broken in 2.4.2) Clarifying change in config file ordering particularly with respect to spring.config.location and profile-specific files Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: wiki-documentation A documentation update required on the wiki
Projects
None yet
Development

No branches or pull requests

3 participants