File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Head First Android this week in the Android forum!
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

expected single match bean but found two exception

Don boscoo

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 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}"/>

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.

Alexander Ryzhikov

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

Joined: Dec 28, 2007
Posts: 2270

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

Joined: Feb 05, 2001
Posts: 17271

You mean it to be.

Roberto Perillo wrote:

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
It is sorta covered in the JavaRanch Style Guide.
subject: expected single match bean but found two exception
It's not a secret anymore!