aspose file tools*
The moose likes Spring and the fly likes Spring @Autowired Multiple Declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring @Autowired Multiple Declarations" Watch "Spring @Autowired Multiple Declarations" New topic
Author

Spring @Autowired Multiple Declarations

Sreenivas Reddy Tatikunta
Greenhorn

Joined: Aug 23, 2011
Posts: 24

Dear All,

Please suggest me, can i use @Autowired in the following ways.

@Autowired
private A a;
private B b;

(or)

@Autowired
private A a;

@Autowired
private B b;

Thanks in Advance

Best Regards,
Sreenivas Reddy.Tatikunta
Sreenivas Reddy Tatikunta
Greenhorn

Joined: Aug 23, 2011
Posts: 24

Please help me out .. this is urgent requirement




Regards,
Sreenivas Reddy.Tatikunta
Dattatraya Tembare
Greenhorn

Joined: Feb 01, 2009
Posts: 10
I'm sure about second approach; it will work perfectly but not sure about performance point of view which is better.
@Autowired
private A a;

@Autowired
private B b;

For now you can start you work ....

Go though the Spring documentation there are several ways to use it.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 973
    
    5



You may think this style works but if you try it, you will find that b is not autowired.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

James Boswell wrote:

You may think this style works but if you try it, you will find that b is not autowired.


Nor should it work. Annotation apply only to immediate elements. It would be very confusing if annotations started to cascade. If it did, we'll need a @StopAutowired


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring @Autowired Multiple Declarations
 
Similar Threads
Is not autowire a another type of dependendcy injection?
expected single match bean but found two exception
Not able to Autowire simple class.
Issue in annotating DAO using spring 3.0
Error: Bean property 'userDAO' is not writable or has an invalid setter method.