Spring wiring conditional to an environment

后端 未结 3 1754
天涯浪人
天涯浪人 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 17:59

    You can injection both implementation and choose which one you need by parameter {spring.profiles.active}, such like this code :

    @autowired
    private Car Toyota;
    @autowired
    private Car Bmv;
    
    public Car getCar(){
      if(spring.profiles.active is local){
            return Toyota;
      }else{
            return  bmv;
      }
    }
    

提交回复
热议问题