Autowiring two different beans of same class

后端 未结 2 1905
感情败类
感情败类 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条回答
  • 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;
    
    0 讨论(0)
  • 2020-12-23 17:35
    @Autowired
    @Qualifier("jedisConnector")
    JedisConnector beanA;
    
    @Autowired
    @Qualifier("jedisConnectorPOD")
    JedisConnector beanB;
    
    0 讨论(0)
提交回复
热议问题