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
{{ message }}
Repository navigation
Problem when including spring profiles with logical operators #16303
Profile expressions (and negated profiles) get processed last, i.e. once we already know the profiles activated and included by the config files. If the YAML document that's activated by a profile expression itself contains a spring.profiles.include, that doesn't get processed at the moment.
We'd have to go over the config files again to look for documents matching the profiles included by the expression. Let's see if the rest of the team thinks this is something we should fix.
I have a fix for this here but this is turning out to get a bit complicated because of the way included profiles are supposed to be ordered. For example, look at the configuration below:
spring.profiles: aspring.profiles.include: c
---
spring.profiles: a & bspring.profiles.include: d,e
---
spring.profiles: dspring.profiles.include: f
---
Given that profiles a and b are active, the above configuration will lead to a profile order of a, c, b, d, e, f, whereas one might expect it to be a, c, b, d, f, e. There are a lot of corner cases when it comes to profiles specific files/YAML documents and include profiles. We need to take a step back and redefine the rules, which will lead to a possible overhaul of this part of the code. We can tackle this in 2.3.x once we have a better idea of what it should look like.
Spring Boot 2.4 has overhauled config processing. See this blog post for details. Since the spring.profiles.include property won't be supported going forward you'll need to find a different way to do what you want.
I would suggest using @Profile("a & b") directly in your code or adding an EnvironmentPostProcessor to set new profiles based on the existing ones.
I'm going to close this one for now, but if you find there's an obvious use-case that we're missing from the new code then please comment back here and we can have another look. We'll need a bit more background about what's driving the need for the includeAandB profile in the first place.
Activity
mbhave commentedon Mar 26, 2019
Profile expressions (and negated profiles) get processed last, i.e. once we already know the profiles activated and included by the config files. If the YAML document that's activated by a profile expression itself contains a
spring.profiles.include, that doesn't get processed at the moment.We'd have to go over the config files again to look for documents matching the profiles included by the expression. Let's see if the rest of the team thinks this is something we should fix.
mbhave commentedon Mar 27, 2019
Based on the complexity of the fix we can decide whether it should go in
2.1.xor2.2.x.mbhave commentedon Apr 5, 2019
I have a fix for this here but this is turning out to get a bit complicated because of the way included profiles are supposed to be ordered. For example, look at the configuration below:
Given that profiles
aandbare active, the above configuration will lead to a profile order ofa, c, b, d, e, f, whereas one might expect it to bea, c, b, d, f, e. There are a lot of corner cases when it comes to profiles specific files/YAML documents and include profiles. We need to take a step back and redefine the rules, which will lead to a possible overhaul of this part of the code. We can tackle this in2.3.xonce we have a better idea of what it should look like.philwebb commentedon Oct 23, 2020
Spring Boot 2.4 has overhauled config processing. See this blog post for details. Since the
spring.profiles.includeproperty won't be supported going forward you'll need to find a different way to do what you want.I would suggest using
@Profile("a & b")directly in your code or adding anEnvironmentPostProcessorto set new profiles based on the existing ones.I'm going to close this one for now, but if you find there's an obvious use-case that we're missing from the new code then please comment back here and we can have another look. We'll need a bit more background about what's driving the need for the
includeAandBprofile in the first place.