2
實現數據源代理我目前的應用程序,我配置數據源對象如春XML,即通過dataSourceReal在dataSourceProxy對象創建的。
監聽器和過濾器已正確配置,如文檔中所示。
的Spring XML文件:用於JNDI名稱
<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>
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 anotation嗎? –
我沒有使用此配置的@Autowired註釋。 –