Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

expected single match bean but found two exception

 
Don boscoo
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can you show a part of code, where you use this declared bean?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Don!

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

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic