Hi,
I recently encountered an issue in multi-profile application. I have two profiles active in this order profile1, profile2,
profile1:
spring:
cloud:
vault:
enabled: true
fail-fast: true
authentication: token
uri: https://some.uri
token : some-token
profile2:
spring:
config:
import: vault://some-vault/path
When trying to run application import is resolved as empty, but when I change the order in which profiles are applied, the import is fetched as it is supposed to. I think it is counter intuitive as I thought this should be loaded in the same order as the profiles are declared. I believe is because of that line in ConfigDataImporter as it is iterating the candidates from the end.
My main question is why it is designed like this? Can this be fixed/changed?
https://github.com/spring-projects/spring-boot/blob/47cac96dfe89b9b2e87b4b39d58e22a0e1b04c8d/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataImporter.java#L117
Comment From: wilkinsona
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config.files.profile-specific
Profile-specific properties are loaded from the same locations as standard application.properties, with profile-specific files always overriding the non-specific ones. If several profiles are specified, a last-wins strategy applies. For example, if profiles prod,live are specified by the
spring.profiles.activeproperty, values inapplication-prod.propertiescan be overridden by those inapplication-live.properties.
Iterating candidates in the opposite direction would result in a first-wins strategy.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.