wood burning stoves 2.0*
The moose likes Spring and the fly likes expected single match bean but found two exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "expected single match bean but found two exception" Watch "expected single match bean but found two exception" New topic
Author

expected single match bean but found two exception

Don boscoo
Greenhorn

Joined: Sep 20, 2010
Posts: 28
Hi All,

I want to have two datasources for my application, one which connects to oracle and the other to sql server. I have them as two seperate xml files imported in the app-config.xml

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>


<bean id="sqlDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.sql.driver}"/>
<property name="url" value="${db.sql.url}"/>
<property name="username" value="${db.sql.username}"/>
<property name="password" value="${db.sql.password}"/>
</bean>

Now am getting an exception that says

Could not autowire method: public void com.pdfscan.disconnectOrders.ProductDetailsItemDaoImpl.setsqlDataSource(javax.sql.DataSource); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: [dataSource, sqlDataSource]

Please help me resolving this.

Thanks.
Alexander Ryzhikov
Greenhorn

Joined: Mar 24, 2011
Posts: 1
Hi,
can you show a part of code, where you use this declared bean?
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Howdy, Don!

Champ, do you have somewhere in your code something like this?



Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

You mean it to be.

Roberto Perillo wrote:


To fix the problem you can add @Qualifier("sqlDataSource") or @Qualifier("dataSource") just below your @Autowired

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
Consider Paul's rocket mass heater.
 
subject: expected single match bean but found two exception