I checked many tutorials but could not find a satisfactory answer.Does this annotation is performing Dependency injection of the properties.I have heard that this can be applied to a method,constructor or field but for what purpose.
Asked
Active
Viewed 1.7k times
1
-
@Jack: This is not a duplicate, the focus of both questions differs a lot. – Ralph Aug 06 '13 at 06:20
-
I would recommend using the @Inject annotation going forward. – sunny Aug 06 '13 at 06:27
-
It's a very broad subject. Don't check tutorials to get the whole picture. Check the spring reference. More specifically the section on [`@Autowired`](http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-autowired-annotation) – Bart Aug 06 '13 at 06:33
2 Answers
6
The @Autowired
annotation is performing Dependency Injection.
If @Autowired
is applied to
- a field: then the dependency is stored in this field
- a setter: then the setter is invoked, with the parameter that is determined by the same algorithm like for the field dependency injection
- a constructor: then the constructor is invoked with the parameters determined by the same algorithm like for the field dependency injection
0
We use @Autowired for :
a. Less abstraction in the system .
b. When Spring finds an @Autowired annotation used with setter methods, it tries to perform byType autowiring on the method.

Shuhail Kadavath
- 448
- 3
- 13
-
Refer to : http://www.tutorialspoint.com/spring/spring_autowired_annotation.htm for more i nfo – Shuhail Kadavath Aug 06 '13 at 06:25