In my application I use several profiles to make certain beans eligible for autowiring. What I'm missing is the possibility to make a bean eligible for autowiring when a certain profile is NOT active.
The best way of doing it that I thought about is like this:
- Let's suppose we have a list of all possible profiles, e.g. {A, B, C, D}.
- Profiles active for particular execution are {A, C}.
- What I do is I create artificial profiles for all possible profiles which are not active. In the example case I would create {not_B, not_D} profiles.
- The beans I want to be active based on not active profile
X
I make active for profilenot_X
. In my case if I wanted a bean to be eligible for autowiring when profile B is not active, I would annotate them@Profile("not_B")
This solution however requires an up-front knowledge about all possible profiles.
Can you think of any better solution?