1. 應用範圍。redis
同一個redis manager的不一樣初始化對象code
<bean id="jedisPaopaoDataPoolManager" class="com.qiyi.paopao.common.jedis.JedisConsistencyPoolManager">
<bean id="jedisCirclePoolManager" class="com.qiyi.paopao.common.jedis.JedisConsistencyPoolManager">
在代碼中直接注入對象
@Autowired private JedisConsistencyPoolManager jedisPaopaoDataPoolManager;
2. it
我有一個包裝一個鏈接池的類,該類從彈簧配置獲取其鏈接細節,以下所示:class
<bean id="jedisConnector" class="com.legolas.jedis.JedisConnector" init-method="init" destroy-method="destroy"> <property name="host" value="${jedis.host}" /> <property name="port" value="${jedis.port}" /> </bean>
此bean隨後用於服務,而且自動鏈接@Autowire註釋。配置
個人問題是,我如何複製這個bean並給它不一樣的鏈接細節,而後@Autowire它的服務。
意思除了上面我將會有:aop
<bean id="jedisConnectorPOD" class="com.legolas.jedis.JedisConnector" init-method="init" destroy-method="destroy"> <property name="host" value="${jedis.pod.host}" /> <property name="port" value="${jedis.pod.port}" /> </bean>
並在服務中:註釋
@Autowired //bean of id jedisConnector JedisConnector beanA; @Autowired //bean of id jedisConnectorPOD JedisConnector beanB;
您能夠將@Autowired與@Qualifier組合,但在這種狀況下,而不是@Autowired,我建議使用@Resource:注入
@Resource(name="jedisConnector") JedisConnector beanA; @Resource(name="jedisConnectorPOD") JedisConnector beanB;
甚至更簡單:di
@Resource JedisConnector jedisConnector; @Resource JedisConnector jedisConnectorPOD;