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

Add note about change in processing order of configuration files to release notes #24497

Closed
philwebb opened this issue Dec 14, 2020 · 19 comments
Closed
Labels
status: superseded An issue that has been superseded by another

Comments

@philwebb
Copy link
Member

See https://spring.io/blog/2020/08/14/config-file-processing-in-spring-boot-2-4#comment-5188826974

project/application.yml:

some-field: value

project/src/test/resources/application-test.yml:

some-field: value2
@ActiveProfiles("test")
TestClass...

@Value("${some-field}")

String someField;

When the test is run with spring boot 2.4.1 the value from application.yml is injected.

When the test is run with spring boot 2.3.6 the value from application-test.yml is injected.

When the test is run with spring boot 2.4.1 and spring.config.use-legacy-processing: true the value from application-test.yml is injected.

@philwebb philwebb added the status: waiting-for-triage An issue we've not yet triaged label Dec 14, 2020
@mbhave mbhave added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 15, 2020
@mbhave mbhave added this to the 2.4.x milestone Dec 15, 2020
@mbhave
Copy link
Contributor

mbhave commented Dec 16, 2020

@philwebb How do our smoke tests pass in that case?

@encircled
Copy link
Contributor

I can't reproduce the reported issue in 2.4.1, nor in current master branch

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Dec 17, 2020
@philwebb
Copy link
Member Author

I've asked the OP to provide a sample

@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Dec 24, 2020
@ibiko
Copy link

ibiko commented Dec 28, 2020

I have packaged the maven project as a zip file.
boot-2.4.1-config-bug.zip

@ibiko
Copy link

ibiko commented Dec 28, 2020

The behavior is reproducible when the spring.config.use-legacy-processing is set to false.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Dec 28, 2020
@encircled
Copy link
Contributor

Hi, thanks for providing the sample.

Still can't reproduce your issue thou, I'm getting value1: value1-test regardless of value in application.yml and spring.config.use-legacy-processing. What OS/JVM are you using?

@ibiko
Copy link

ibiko commented Dec 28, 2020

It happens on two Systems:
System1:
OS: Linux Mint 20 Cinnamon
JDK: openjdk 14 2020-03-17
System2:
OS: openSuse Tumbleweed
JDK: openjdk 11.0.9.1 2020-11-04

@ibiko
Copy link

ibiko commented Dec 29, 2020

Have you modified the property 'spring.config.use-legacy-processing' in /application.yml when testing or have you created a new property in /src/main/resources/application.yml?

@ibiko
Copy link

ibiko commented Dec 29, 2020

In my tests it is enough to just modify the existing property in /application.yml to get the two different behaviors.

@pearsonradu
Copy link

I created a project to demonstrate this bug https://github.com/pearsonradu/spring-boot-24497. This project showcases the context I was in when I discovered this issue.

Essentially there are two spring profiles, test and dev. The application will run successfully with the dev profile active and use spring.config.import to import an external property file. Running the application with the test profile fails, saying

***************************
APPLICATION FAILED TO START
***************************

Description:

Config data location 'file:./config/additional.yaml' does not exist

Action:

Check that the value 'file:./config/additional.yaml' at class path resource [application.yaml] - 14:13 is correct, or prefix it with 'optional:'


Process finished with exit code 1

Additional, I have a test case with @ActiveProfiles("test") that will fail to run with the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Config data location 'file:./config/additional.yaml' does not exist

Action:

Check that the value 'file:./config/additional.yaml' at class path resource [application.yaml] - 14:13 is correct, or prefix it with 'optional:'

@encircled
Copy link
Contributor

Hi,
@ibiko I see now, let me check it again

@pearsonradu this is a slightly different issue, I've raised a separate issue for that #24798

@encircled
Copy link
Contributor

Such behavior is inline with the documentation https://docs.spring.io/spring-boot/docs/2.4.0/reference/htmlsingle/#boot-features-external-config

Config data files are considered in the following order:

1. Application properties packaged inside your jar (application.properties and YAML variants).

2. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).

3. Application properties outside of your packaged jar (application.properties and YAML variants).

4. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).

The change is effective from 2.4.0 as part of #22497
@philwebb I believe this should have been pointed out in the changelog

@mbhave
Copy link
Contributor

mbhave commented Jan 13, 2021

Thanks for the sample @ibiko.

@encircled Thanks for the suggestion. We should add a note about the change in behavior to the release notes.

@mbhave mbhave added type: wiki-documentation A documentation update required on the wiki and removed status: feedback-provided Feedback has been provided type: bug A general bug labels Jan 13, 2021
@mbhave mbhave changed the title Tests with @ActiveProfiles do not pick up profile specific config data files Add note about change in processing order of configuration files to release notes Jan 13, 2021
@ideazinfinite
Copy link

Such behavior is inline with the documentation https://docs.spring.io/spring-boot/docs/2.4.0/reference/htmlsingle/#boot-features-external-config

Config data files are considered in the following order:

1. Application properties packaged inside your jar (application.properties and YAML variants).

2. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).

3. Application properties outside of your packaged jar (application.properties and YAML variants).

4. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).

The change is effective from 2.4.0 as part of #22497
@philwebb I believe this should have been pointed out in the changelog

Could you please clarify on how OP's issue about using @ActiveProfiles("test") annotation being ignored is in line with the documentation? I too am running into a similar issue as OP where the profile value set in @ActiveProfile is ignored and I can confirm that this behavior has changed between spring boot versions 2.4.1 and 2.4.2.

@mbhave
Copy link
Contributor

mbhave commented Jan 16, 2021

It's not that the @ActiveProfiles("test") is being ignored. It's the presence of an application.yml outside of the packaged jar that causes this behavior because of the change in processing order of configuration files.

If you're seeing that the @ActiveProfile is ignored, could you provide a sample application that we can run to reproduce the issue?

@ideazinfinite
Copy link

It's not that the @ActiveProfiles("test") is being ignored. It's the presence of an application.yml outside of the packaged jar that causes this behavior because of the change in processing order of configuration files.

If you're seeing that the @ActiveProfile is ignored, could you provide a sample application that we can run to reproduce the issue?

I think I get that part, up until 2.4.1 having @ActiveProfile inside of a class was able to override the active profile but since upgrading to 2.4.2, it is being ignored and the ordering described above seems to apply.

@mbhave
Copy link
Contributor

mbhave commented Feb 4, 2021

@ideazinfinite That is not the behavior I'm seeing with the sample provided above. I see the same behavior with 2.4.1 and 2.4.2. If you think you have found a bug in 2.4.2, please raise another issue with a small sample that can be run to reproduce it.

@mbhave
Copy link
Contributor

mbhave commented Feb 4, 2021

Closing this issue as this has already been documented in the migration guide.

@mbhave mbhave closed this as completed Feb 4, 2021
@mbhave mbhave removed this from the 2.4.x milestone Feb 4, 2021
@mbhave mbhave added status: superseded An issue that has been superseded by another and removed type: wiki-documentation A documentation update required on the wiki labels Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

7 participants