spring多数据源注入问题 100分求解
我的配置文件:
<?xml version="1.0" encoding="GB2312"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="cls.hlw"/>
<bean class="cls.hlwp.jkpro.util.db.InitializeBean" lazy-init="false"/>
<bean id="datasource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close" scope="singleton" p:minIdle="1" p:maxActive="20" p:initialSize="1"
p:maxWait="20000" p:username="hlwp_bidata" p:password="lhf0op" p:url="jdbc:oracle:thin:hlwp_bidata/lhf0op@192.168.17.90:1521:cnfc">
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="120" />
<property name="testWhileIdle" value="true" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="validationQuery" value="SELECT 1+1 from dual" />
<property name="connectionProperties" value="config.decrypt=false" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="50" />
</bean>
<!-- 定义默认事务控制过程 -->
<tx:annotation-driven transaction-manager="tx" />
<bean id="tx" p:dataSource-ref="datasource" lazy-init="true"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" />
<bean id="jdbcTemplate" p:resultsMapCaseInsensitive="true" lazy-init="default"
class="org.springframework.jdbc.core.JdbcTemplate" p:dataSource-ref="datasource" />
<bean id="seqCookie" class="org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer"
p:incrementerName="seq_cookieid" p:dataSource-ref="datasource"/>
<bean id="datasource2" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close" scope="singleton" p:minIdle="1" p:maxActive="20" p:initialSize="1"
p:maxWait="20000" p:username="HLWP_PVDATA" p:password="lhf0op" p:url="jdbc:oracle:thin:HLWP_PVDATA/lhf0op@192.168.17.90:1521:cnfc">
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="120" />
<property name="testWhileIdle" value="true" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="validationQuery" value="SELECT 1+1 from dual" />
<property name="connectionProperties" value="config.decrypt=false" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="50" />
</bean>
<!-- 定义默认事务控制过程 -->
<tx:annotation-driven transaction-manager="tx2" />
<bean id="tx2" p:dataSource-ref="datasource2" lazy-init="true"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" />
<bean id="jdbcTemplate" p:resultsMapCaseInsensitive="true" lazy-init="default"
class="org.springframework.jdbc.core.JdbcTemplate" p:dataSource-ref="datasource2" />
<bean id="seqCookie2" class="org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer"
p:incrementerName="seq_cookieid" p:dataSource-ref="datasource2"/>
</beans>
dao:
@Repository
public class QdyhDao {
@Autowired @Qualifier("jdbcTemplate")
public JdbcTemplate jdbcTemplate;
@Autowired @Qualifier("jdbcTemplate2")
public JdbcTemplate jdbcTemplate2;
错误信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'qdyhDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.jdbc.core.JdbcTemplate cls.hlwp.jkpro.funcpoint.dxqd.qdyh.QdyhDao.jdbcTemplate2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=jdbcTemplate2)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
.................
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.jdbc.core.JdbcTemplate cls.hlwp.jkpro.funcpoint.dxqd.qdyh.QdyhDao.jdbcTemplate2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=jdbcTemplate2)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 44 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=jdbcTemplate2)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1103)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:963)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 46 more