| 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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
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: 576
|
|
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
|
 |
 |
|
|
subject: Spring @Autowired Multiple Declarations
|
|
|