This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
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: 2258
    
    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: 17249
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: expected single match bean but found two exception
 
Similar Threads
how to add dditional properties to DB url in Spring ?
IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
Spring + JPA + Hibernate and multiple Database connection
New to Spring
Spring - Connection Problem in some Unit Tests