This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Software Teaming: A Mob Programming, Whole-Team Approach and have Woody Zuill and Kevin Meadows on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

No unique bean of type is defined: expected single matching bean but found 2

 
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand how this problem can occur but in this case I have not made any of the classic mistakes

The error is expected single matching bean but found 2: [fundRepositoryImpl, fundRepository] In this case I just have a single bean fundRepositoryImpl implementing a single interface



This implements the FundRepository which is labled with the @Repository


which implements DomainRepository




I have not id any of the beans in the spring context.



Thanks for any help
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Why you have these lines two times in your configuration?




http://www.javabeat.net/2013/03/spring-tutorials/
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Tony,

"No unique bean of type is defined: expected single matching bean but found 2" error normally appear at the time of wiring. As you are using component scan, I assume there should be more code where the error might be appearing during wiring.

If above is not the case, Can you please provide the error stack trace. That would help us in identifying the root cause of the problem?

As suggested by Krishna, please remove duplicate entry from you xml file.

Regards
Salil Verma
 
Krishna Srinivasan
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As salil mentioned, some time when spring trying to wire the bean two times because it is declared twice, there is chance of getting this error.
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have removed the duplicate entries, also in the code made the follwoing changes

Removed @Repository from the interface


Added it to the class


Still getting the error


 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I only get the error if i implement


The offending code is
 
Tony Evans
Ranch Hand
Posts: 681
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok worked it out, as I am using JpaRepository I do not need to create a concrete implemention class its using the bean FundRepository as the repository type.
By adding a concrete repository class FundRepositoryImpl which is defined as a repository @Repository

Spring then saw two repository type beans FundRepositoryImpl and FundRepository .

The solution is to not define a concrete class FundRepositoryImpl if using JpaRepository.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic