• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

When does the stereotype name come into play ?

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day,

I have a repository class as below, and i wonder whether the stereotype name is important ? as i put any name to replace "userRepository", it still running fine, could someone please enlighten me ?



Thanks
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It comes into play when multiple beans of same type are instantiated.

Spring's default behaviour is type based autowiring. When it sees @Autowired, it just looks for the bean class that matches that type and has same class name as the field name.
If you create a second UserRepository implementation and it too is annotated with @Repository, it'll get instantiated but wiring will fail with an exception on the lines of "expected single match but found 2".
You'll have to then explicitly tell Spring which one of them to wire by adding @Qualifier("name") alongside @Autowired.
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic