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

spring.config.activate.on-profile cannot be used in profile specific file #24990

Closed
markusheiden opened this issue Jan 25, 2021 · 5 comments
Closed
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@markusheiden
Copy link

We use the "multi properties files in one" feature of Spring Boot 2.4.

With the change from Spring Boot 2.4.1 to 2.4.2 the following does no longer work:

application-xxx.properties

yyy=1
#---  
spring.config.activate.on-profile=zzz
yyy=2
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.config.activate.on-profile' imported from location 'class path resource [application-xxx.properties]' is invalid in a profile specific resource [origin: class path resource [application-xxx.properties] - 28:35]
	at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:121) ~[spring-boot-2.4.2.jar:2.4.2]
	at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
	at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1087) ~[?:?]
	at org.springframework.boot.context.config.InvalidConfigDataPropertyException.throwOrWarn(InvalidConfigDataPropertyException.java:118) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.context.config.ConfigDataEnvironment.checkForInvalidProperties(ConfigDataEnvironment.java:349) ~[spring-boot-2.4.2.jar:2.4.2]

If I incorrectly used this feature I apologize upfront.

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

wilkinsona commented Jan 25, 2021

Thanks for the report. I was going to close this as a duplicate of #24941 but this case is a little different.

The change in behaviour is due to #24733. The intent of this issue was to start failing when a property is used that was previously being silently ignored. However, in this case the property wasn't being silently ignored. With the example above, when the xxx and zzz profiles are active, Spring Boot 2.4.1 sets the value of yyy to 2. In 2.4.2, the application fails to start.

We'll need to decide how we want to handle spring.config.activate.on-profile when used in a profile-specific file.

@wilkinsona wilkinsona added for: team-attention An issue we'd like other members of the team to review type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 25, 2021
@wilkinsona wilkinsona added this to the 2.4.x milestone Jan 25, 2021
@markusheiden
Copy link
Author

It would be nice, if you consider the combination of profile specific files with on-profile as feature, because it allows for better structuring thus smaller properties files.

@wilkinsona
Copy link
Member

We're going to try to support spring.config.activate.on-profile in a profile-specific file.

@larsduelfer
Copy link

larsduelfer commented Jan 26, 2021

If I get the intention right from @markusheiden it would indeed be benefitial to have multiple yaml files contains application properties and each files is sub-structured in sections having their own value for spring.config.activate.on-profile. This way, larger setups with lot's of properties would be very well supported.

Example:

application-logging.yaml

spring:
  config:
    activate:
      on-profile: production
logging:
  level:
    ...
---
spring:
  config:
    activate:
      on-profile: staging
logging:
  level:
    ...
---
spring:
  config:
    activate:
      on-profile: local
logging:
  level:
    ...

You can then organize all logging configuration properties in one property file and depending on the active profile, the part of the yaml file is used.

@wilkinsona: Is that what you have in mind by saying "We're going to try to support spring.config.activate.on-profile in a profile-specific file." in your comment above? Thanks in advance for a short answer on this.

If I understand correctly how it works in 2.4.1, you need to have any of the following profile combinations in your list of active profiles: "logging, production", "logging, staging" or "logging,local". Is this correct? I never tried this myself with 2.4.1 since we are currently upgrading directly to 2.4.2.

Another option would be, to ignore the suffix of the filename application-suffix.yaml and just interpret this file as another application.yaml. This way, the files won't get too long and the profile-specific config for logging is just activated by having any of the following profiles in the list of active profiles: "staging", "production" or "local".

@wilkinsona
Copy link
Member

@larsduelfer Short answer: yes.

Slightly longer answer: Yes, although you may want to use a spring.config.import to pull in a configuration file that encapsulates all your logging-related properties without having to activate the logging profile.

@philwebb philwebb self-assigned this Jan 27, 2021
@philwebb philwebb changed the title spring.config.activate.on-profile regression in Spring Boot 2.4.2 spring.config.activate.on-profile cannot be used in profile specific file Jan 27, 2021
@philwebb philwebb modified the milestones: 2.4.x, 2.4.3 Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants