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

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic