wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 15299

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: 17249

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 - Two Laptop Bag - Tube Organizer
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: http://aspose.com/file-tools
subject: @autowired annotation
Similar Threads
Spring @Autowired Multiple Declarations
Error: Bean property 'userDAO' is not writable or has an invalid setter method.
Can we pass a dynamic list of ref-beans to a bean in spring application context file?
@Autowired not working in JUnit using spring 2.5