Apologies if this has been reported before, couldn't find any StackOverflow posts or GitHub issues.
When attempting to use spring.config.activate.on-cloud-platform, there is no mechanism available to simply state "If not running on a cloud platform" without forcibly setting the NONE value via spring.main.cloud-platform through some other mechanism.
https://github.com/spring-projects/spring-boot/blob/152acf8a59ac952340ab653c61b5dca9649dacf7/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java#L128
This is undesirable for libraries providing configuration files with default values (e.g. through multi-documents) for scenarios when the consumers is running on a cloud platform and for when they aren't, as it forces one of the following scenarios:
- Force consumers to specify
spring.main.cloud-platform: NONEwhen running locally (ex: through their application-{local-env-name}.yml) - Abandon
spring.config.activate.on-cloud-platformand multi-document config files, and conditionally load the properties through custom beans and manual CloudPlatform checks - Abandon
spring.config.activate.on-cloud-platformand use a different, likely more unreliable, property condition, such asspring.config.activate.on-profile: 'DEV | LOCAL | NO-PLATFORM'
Proposed change:
private boolean isActive(CloudPlatform cloudPlatform) {
return this.onCloudPlatform == null
|| (this.onCloudPlatform == NONE && cloudPlatform == null)
|| this.onCloudPlatform == cloudPlatform);
}
Comment From: wilkinsona
We think this makes sense but we're unsure about when to make the change. It could be considered a bug, in which case 3.1.x would be an option if the risk isn't too great. WDYT, @philwebb?
Comment From: philwebb
I think we should consider this an enhancement.
The original intention of the spring.config.activate.on-cloud-platform property was to allow additional or override configuration for a specific cloud platform, I don't think we really considered none being used there.
The CloudPlatform.NONE enum was primary added to allow users to prevent our detection logic from running. From the javadoc:
No Cloud platform. Useful when false-positives are detected.
In other words, if we're guessing wrong for whatever reason then set this to tell us.
There is a subtle distinction between CloudPlatform.getActive(...) returning null and NONE. One means that we didn't detect a cloud platform, the other means the user actively stopped us from trying.
I think it's fine for us to change the isActive code in a minor release, since it feels like the change makes things more logical. I don't think we should do it in a patch release just in case someone is relying on the existing behavior.
Comment From: wilkinsona
Closing in favor of https://github.com/spring-projects/spring-boot/pull/38510 that we'll merge in 3.3.