You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For would like to have certain YAML documents activate only if two profiles are enabled. At the same time I may define a YAML documents for each Profiles. The desired effect is that YAML document activated by the conditional & of the two profiles should have a higher precedence then single profile YAML documents.
Ex.) If spring.profiles.active=ProfileA,ProfileB, I would like the value of spring.message to be "ProfileA an ProfileB activated!!!"
I would expect the positive profiles in an expression would contribute to the precedence but not anything negative.
For example spring.profiles: ProfileA & ProfileB & !ProfileC I would like this YAML document to have higher precedence then ProfileA and ProfileB. The precedence of ProfileC does not matter because it is activated.
Thanks for the suggestion but, unfortunately, I don’t think we can implement this. It would break the documented behaviour:
The YAML documents are merged in the order in which they are encountered. Later values override earlier values.
This area of the codebase is one of the most complex and problematic and this documented behaviour has some known issues (see #18199, for example). We will hopefully be able resolve #18199 in due course.
Even if it what’s proposed here was not a breaking change, I think it would be foolhardy to add to the existing complexity to order the documents based on the specificity of their profile expressions. It would be difficult to implement and I think it would be difficult for users to understand. For example, if profile b is active, does a & b or c & b win?
The order in which they occur part confused me because it did not matter where in the YAML file I put the spring.profiles: ProfileA & ProfileB YAML document. It always had lower priority.
Regardless thanks for you time.
I revisited it and a better workaround and maybe a more explicit way would be to setup the profiles like this instead:
For would like to have certain YAML documents activate only if two profiles are enabled. At the same time I may define a YAML documents for each Profiles. The desired effect is that YAML document activated by the conditional
&
of the two profiles should have a higher precedence then single profile YAML documents.Ex.) If
spring.profiles.active=ProfileA,ProfileB
, I would like the value ofspring.message
to be "ProfileA an ProfileB activated!!!"I would expect the positive profiles in an expression would contribute to the precedence but not anything negative.
For example
spring.profiles: ProfileA & ProfileB & !ProfileC
I would like this YAML document to have higher precedence then ProfileA and ProfileB. The precedence of ProfileC does not matter because it is activated.I have attached an example project:
profile-expressions.zip
Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-multi-profile-yaml
The text was updated successfully, but these errors were encountered: