aspose file tools*
The moose likes Spring and the fly likes How does autowiring work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How does autowiring work?" Watch "How does autowiring work?" New topic
Author

How does autowiring work?

Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
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?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does autowiring work?