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
Profile activation: not operator does not work consistently [SPR-16465] #21010
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply
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.
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).
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.
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.
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.
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.
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.
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply
Activity
spring-projects-issues commentedon Feb 6, 2018
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.
spring-projects-issues commentedon Feb 7, 2018
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).
spring-projects-issues commentedon Feb 7, 2018
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.
spring-projects-issues commentedon Feb 7, 2018
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.
spring-projects-issues commentedon Feb 7, 2018
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.
spring-projects-issues commentedon Feb 7, 2018
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.
spring-projects-issues commentedon Feb 7, 2018
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.