• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How does autowiring work?

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does Spring container scans all objects as given in config file via package pattern(e.g. com.mycomp.myproj.*) and finds out which class is implementing which interface ?How is it done so efficiently?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does scan all classes that match the given pattern - but it looks for annotations instead of interfaces. Details are covered in this section of the Spring docs.

It's also not necessarily "efficient" - it just loads the classes and uses reflection to find matching annotations. To prevent long startup times, it's better to be very specific in the pattern that you tell it to match - if you pass it a package path that contains a bunch of classes, it will take time to scan all of them.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nathan Pruett wrote:It does scan all classes that match the given pattern - but it looks for annotations instead of interfaces. Details are covered in this section of the Spring docs.

It's also not necessarily "efficient" - it just loads the classes and uses reflection to find matching annotations. To prevent long startup times, it's better to be very specific in the pattern that you tell it to match - if you pass it a package path that contains a bunch of classes, it will take time to scan all of them.



Actually, you just describe component-scan not autowiring. ;)

For autowiring, Spring looks at just the Spring Beans that it created for an object of the type that needs to be injected into the other bean. You don't/can't filter this. Spring will go through all your beans that it knows about, it won't go outside of those classes.

Mark
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic