default-autowire="byType"冲突解决

当我这样配置p6spy时,

<bean id="dataSourceImpl" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<property name="url"
			value="jdbc:oracle:thin:@顶顶顶" />
		<property name="username" value="顶顶顶" />
		<property name="password" value="顶顶顶" />
	</bean>
	<!-- 用p6spy 在console显示变量绑定后的真实sql 与ResultSet,方便开发 -->
	<bean id="dataSource" class="com.p6spy.engine.spy.P6DataSource">
		<constructor-arg index="0" ref="dataSourceImpl" />
	</bean>

 系统报如下错误,原因是因为default-autowire="byType"。冲突了,把系统改成default-autowire="byName"要改好多地方,显然不现实。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSourceImpl, dataSource]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:796)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1152)

 

解决方案:

	<bean id="dataSource" class="com.p6spy.engine.spy.P6DataSource">
		<constructor-arg index="0">
			<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
				<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
				<property name="url"
					value="jdbc:oracle:thin:@顶顶顶" />
				<property name="username" value="顶顶顶" />
				<property name="password" value="顶顶顶" />
			</bean>
		</constructor-arg>
	</bean>

你可能感兴趣的:(oracle,sql,bean,jdbc)