Skip to content

Problem when including spring profiles with logical operators #16303

Description

@bondj

Spring Boot v2.1.3.RELEASE

I have an application.yml where I want to include profiles based on logical conditions on what profiles are active. I've attached my application.yml

---
spring.profiles: a & b
spring:
  profiles:
    include:
      - includeAandB
mypropAandB: valueAandB

---
spring.profiles: a
spring:
  profiles:
    include:
      - includeA
mypropA: valueA
---
spring.profiles: b
spring:
  profiles:
    include:
      - includeB
mypropB: valueB

---
spring.profiles: c
spring:
  profiles:
    include:
      - includeC
mypropC: valueC

When I run

SPRING_PROFILES_ACTIVE=a,b ./gradlew bootRun

I get

The following profiles are active: a,includeA,b,includeB

This seems inconsistent, I was expecting a,includeA,b,includeB,includeAandB or possible a,b if the includes were not supported.

Activity

  1. mbhave commented on Mar 26, 2019

    @mbhave
    Contributor

    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.

  2. mbhave commented on Mar 27, 2019

    @mbhave
    Contributor

    Based on the complexity of the fix we can decide whether it should go in 2.1.x or 2.2.x.

  3. added and removed
    for: team-attentionAn issue we'd like other members of the team to review
    on Mar 27, 2019
  4. added this to the 2.1.x milestone on Mar 27, 2019
  5. self-assigned this
    on Mar 27, 2019
  6. mbhave commented on Apr 5, 2019

    @mbhave
    Contributor

    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: a
    spring.profiles.include: c
    ---
    spring.profiles: a & b
    spring.profiles.include: d,e
    ---
    spring.profiles: d
    spring.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.

  7. modified the milestones: 2.1.x, 2.x on Apr 5, 2019
  8. modified the milestones: 2.x, 2.4.x on Jul 31, 2020
  9. self-assigned this
    on Jul 31, 2020
  10. philwebb commented on Oct 23, 2020

    @philwebb
    Member

    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.

  11. added
    status: declinedA suggestion or change that we don't feel we should currently apply
    and removed
    theme: config-dataIssues related to the configuration theme
    on Oct 23, 2020
  12. removed this from the 2.4.x milestone on Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions