Including bean definition when a profile is NOT active

前端 未结 1 637
我寻月下人不归
我寻月下人不归 2021-02-11 12:16

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 certai

1条回答
  •  无人共我
    2021-02-11 12:42

    You can use a not (!) operator... but you have to use Spring 3.2 M1.

    The following syntax is now supported

    
    
    @Profile("A", "!B")
    

    indicating that the element or annotated component should be processed only if profile 'A' is active or profile 'B' is not active.

    See change announced here: Spring Framework 3.2 M1 Released
    The commit is at GitHub: Support not (!) operator for profile selection
    Issue in JIRA: SPR-8728

    If upgrading to Spring 3.2 is not possible for your project, I would recommend not using the @Profile approach and ensuring that the bean is not created in your Spring configuration.

    0 讨论(0)
提交回复
热议问题