Autowiring two different beans of same class

后端 未结 2 1918
感情败类
感情败类 2020-12-23 17:02

I have a class which wraps a connection pool, the class gets its connection details from a spring configuration as shown below:



        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 17:24

    You can combine @Autowired with @Qualifier, but in this case instead of @Autowired, I suggest using @Resource:

    @Resource(name="jedisConnector")
    JedisConnector beanA;
    
    @Resource(name="jedisConnectorPOD")
    JedisConnector beanB;
    

    or even simpler:

    @Resource
    JedisConnector jedisConnector;
    
    @Resource
    JedisConnector jedisConnectorPOD;
    

提交回复
热议问题