【发布时间】:2015-12-06 18:26:20
【问题描述】:
我正在尝试使用来自Here 的当前应用程序实现数据源代理
我在spring xml中配置了datasource对象,即在dataSourceProxy对象中传递dataSourceReal。
侦听器和过滤器已按照文档中的方式正确配置。
Spring xml 文件:
<bean id="dataSourceReal" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS" />
<property name="resourceRef" value="true" />
<property name="lookupOnStartup" value="false" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
<bean id="dataSourceProxy" class="net.ttddyy.dsproxy.support.ProxyDataSource">
<property name="dataSource" ref="dataSourceReal" />
<property name="listener" ref="listeners" />
</bean>
<bean id="listeners" class="net.ttddyy.dsproxy.listener.ChainListener">
<property name="listeners">
<list>
<bean
class="com.my.sql.logging.DataSourceQueryLoggingListener" />
</list>
</property>
</bean>
用于数据源名称的 JNDI 名称的 xml 文件:
<Resource name="jdbc/myDS" auth="Container"
type="javax.sql.DataSource"
maxActive="25" maxIdle="5" maxWait="10000"
username="abc" password="abc"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:myDB"
validationQuery="Select 1 from dual" />
我收到此错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSourceReal, dataSourceProxy]
请帮忙。
【问题讨论】:
-
你在代码中使用@Autowired注解吗?
-
我没有为这个配置使用@Autowired注解。
标签: java hibernate spring-mvc datasource