Can I negate (!) a collection of spring profiles?

前端 未结 4 578
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 14:29

Is it possible to configure a bean in such a way that it wont be used by a group of profiles? Currently I can do this (I believe):

@Profile(\"!dev, !qa, !loc         


        
4条回答
  •  孤城傲影
    2020-12-05 14:41

    You can simply mark RealImp class with @Profile("Production") (or your own profile name) so that you don't need to specify all other profiles.

    Could I just annotate one of them, and stick a @Primary annotation on the other instead?

    Yes, you can use @Primary as well for RealImp class, but ensure that you are using the same concept consistently across the whole project i.e., in other words, if you mark some of the bean real implementation classes (meant for actual production environment) as @Profile("Production") and some of them with @Primary then the project will become in a messy state.

提交回复
热议问题