Spring wiring conditional to an environment

后端 未结 3 1753
天涯浪人
天涯浪人 2020-12-21 17:49

With Spring wiring, if I have multiple implementations of an interface, I can use @Qualifier to specify which one I want.

E.g., assuming that I have a



        
3条回答
  •  梦毁少年i
    2020-12-21 18:08

    Spring 3.1 introduced environment profiles: http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/

    I personally do not like Qualifiers and using them the way you proposed in the code actually couples to the implementation rather than decouple. You can use the @Autowired element like Jason proposed, but couple that with the bean profiles like so:

    and then when you create the environment you specify a profile:

    dispatcher org.springframework.web.servlet.DispatcherServlet spring.profiles.active production

提交回复
热议问题