-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Support not (!) operator for profile selection [SPR-8728] #13370
Comments
Chris Beams commented Hi Tobias, I've been expecting this request :) For the uninitiated, the semantics of To re-iterate your request, you would like to introduce additional boolean operations -- particularly AND -- to indicate that individual Let me note at this point, that OR logic was selected as the only available operation and mapped to the comma (',') delimiter because it is the most reasonable default, i.e. what most users would expect in most situations, reads well, and also provides the most flexibility. You can effectively achieve boolean AND logic simply by nesting
With that said, we understand that this is not an ideal approach if indeed AND logic ends up being commonplace for bean definition profile users. Therefore, we're open to implementing something here, but I would like to see additional votes and concrete use cases before doing so. In the meantime, I hope that the simple alternative above can meet your needs more effectively. Please feel free to rally support for this issue. We'd like to hear from other users. Also note that any such change must also be reflected in the As you can see, this is a seemingly simple request that can quickly spiral into complexity. For that reason, and as mentioned above, I'd like to get more feedback before heading in any one direction. Cheers Chris |
Erwin Vervaet commented Next to AND logic, NOT would also be very useful. <beans profile="normal">...</beans> The downside here is that you need to explicitly activate the 'normal' profile, which can be a bit of a pain. IMHO, it would be more elegant to be able to write something like this: <beans profile="!special">...</beans> If you find yourself in a special situation it makes sense that you need to activate the 'special' profile. |
Chris Beams commented Hi Erwin, For this particular use case, could the You may even rename the default profile to "normal" if you wish through the |
Erwin Vervaet commented Hey Chris, I don't think the default profiles would cover my case. The problem is that we actually have a large number of bean definition profiles (a least 20) and the "just two variants" remark only applies to a few of those. For other cases I need to be explicit and select a particular variant. In other words: I have explicitly activated profiles (Environment.getActiveProfiles()), and as a result the default profiles are no longer considered (AbstractEnvironment.acceptsProfiles()). |
Peter Wilkinson commented I'm with Erwin. I have several components that can run with a 'normal' or 'special' profile and I want to be able to switch between modes on each component individually. At the moment this requires me setting all profiles explicitly. A not operator as Erwin suggested would be very helpful. |
Chris Beams commented ok -- it certainly does look like there's demand for this change. I'm moving the fixVersion to 3.2 M1 so that I can at least take a stab at a NOT operator. I'll also look at the feasibility of full SpEL expression support, but at this point I would favor as simple as possible a set of changes for the reasons I initially listed above. One thing that I'd appreciate feedback on: The current semantics of comma-delimited profile strings is that the comma represents OR logic, e.g.:
indicates that this bean should be registered if Introducing a simple NOT (
would by extension indicate that this bean should be registered if This syntax would also allow for strange loopholes like the following:
in which case the given bean would always be registered. Harmless perhaps, but worth noting. Does anyone see issues with the above? |
Peter Wilkinson commented
|
Erwin Vervaet commented I like the approach. So +1 from me. |
Chris Beams commented
|
Tobias Mattsson opened SPR-8728 and commented
It would be really helpful if the profile attribute could take names of profiles that all has to be active.
For instance:
As for syntax there would need to be a notation that can express both OR and AND, possibly using | and ,
Like:
Even better would be if the syntax was in line with other expressions such as SpEL.
Affects: 3.1 M2
Issue Links:
7 votes, 12 watchers
The text was updated successfully, but these errors were encountered: