Spring wiring conditional to an environment

后端 未结 3 1733
天涯浪人
天涯浪人 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条回答
  •  醉梦人生
    2020-12-21 18:08

    Ah, the solution is actually quite simple:

    @Component
    @Qualifier("Bmv")
    @Profile("!dev")
    public class Bmv implements Car
    

    and

    @Component
    @Qualifier("Toyota")
    @Profile("dev")
    public class Toyota implements Car
    

    This way, the wiring of Car will use Toyota for dev environment, and Bmv otherwise.

提交回复
热议问题