Meaningless Drivel is fun!
The moose likes Other Application Frameworks and the fly likes @autowired annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "@autowired annotation" Watch "@autowired annotation" New topic

@autowired annotation

NareshAnkuskani Kumar
Ranch Hand

Joined: Sep 15, 2005
Posts: 76
Using autowiring mechanism i am planning to establish relationships among the object.

if i annote a property with "@autowired" then should i have to declare the corresponding bean in applicationcontext.xml file.

please let me know.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

No, you shouldn't. Also understand that by using @Autowire, you are not defining relationships in your objects. The relationship already exists via composition. @Autowire is just injecting one object into another object.

GenRocket - Experts at Building Test Data
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

If you are just using @Autowired and not any @Components, then the base beans still need to be declared in your xml.


In order to get the ARepositoryImpl to be injected into AServiceImpl both need <bean> tags.

But the repository will be automatically injected into the service class.

If you have

Then the only thing you need in the xml is the context:component-scan tag to tell Spring which package to scan for @Component annotations. @Repository extends @Component so @Repository is an @Component.



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
NareshAnkuskani Kumar
Ranch Hand

Joined: Sep 15, 2005
Posts: 76
Thanks Mark and others.
I agree. Here's the link:
subject: @autowired annotation
It's not a secret anymore!