Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Feb 3, 2018 · 7 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 3, 2018

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

@spring-projects-issues
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

spring-projects-issues commented 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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants