Skip to content

Profile activation: not operator does not work consistently [SPR-16465] #21010

Closed

Description

@spring-projects-issues

Pushkar Prakash opened SPR-16465 and commented

bcd44f3
As mentioned in the above commit, the following works

<beans profile="p1,!p2">

But, this does not work

<beans profile="!p1,!p2">

Even this does not work.

<beans profile="[{!p1},{!p2}]">

Affects: 3.2.18, 4.3.14, 5.0 GA

Reference URL: bcd44f3

Issue Links:

Referenced from: commits 285b01f, 1444094

Activity

  1. spring-projects-issues commented on Feb 6, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Pushkar Prakash commented

    To explain it a bit more:
    When no profiles are active then the expected configuration of profile="!p1,!p2" works fine.
    However, when if any one of p1 or p2 are active then we hit the failure scenario.

    AbstractEnvironment.acceptsProfiles() method fails to handle the above case.

  2. spring-projects-issues commented on Feb 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This works as designed as far as I can tell: Each of the specified elements is evaluated individually, and the profile condition overall matches if one the element matches. So for "!p1,!p2", it matches for no profile active, for p1 only active, for p2 only active, but not for p1 and p2 active (since both "!p1" and "!p2" do not match in such a scenario).

  3. spring-projects-issues commented on Feb 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Pushkar Prakash commented

    I thought the same when i debugged the code in AbstractEnvironment.
    However, the bean with profile="!p1,!p2" is getting fired when for e.g. p1 is active and p2 is inactive leading to duplication bean creation which throws bean already exists.

    Explicitly naming the bean profiles and activating them will resolve this issue but is not an option due to various reasons.

  4. spring-projects-issues commented on Feb 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    It seems you're assuming 'and' semantics there? It's actually defined as 'or' which is why the overall condition will match if only one of the elements matches, i.e. also if p1 is active and p2 is inactive - since "!p2" matches for the latter part.

  5. spring-projects-issues commented on Feb 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    BTW, we have an improvement request in the backlog asking for an 'and' concatenation option: #17063. That said, I'm afraid it's not planned for any concrete release at this point.

  6. spring-projects-issues commented on Feb 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Pushkar Prakash commented

    You,re right.

    Even a new release is not going to help us as we can't upgrade!

    I am thinking I should be able to hookup a bean at spring startup and set the system property to activate a (explicitly named) profile for each environment.

  7. spring-projects-issues commented on Feb 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Indeed, you might be better off simplying the profile arrangement, pre-selecting a well-defined profile on startup. As for this JIRA issue, I'll mark it as "Works as Designed" then.

  8. added
    type: bug
    status: declined
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: declined

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions