This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "@autowired annotation" Watch "@autowired annotation" New topic
Author

@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
    
    6

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

so


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.

hth

Mark


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
@Autowired not working in JUnit using spring 2.5
Error: Bean property 'userDAO' is not writable or has an invalid setter method.
@PostConstruct
Can we pass a dynamic list of ref-beans to a bean in spring application context file?