Maybe, because of my wrong English, I couldn\'t understand the benefit of using @Autowired annotation.
According to the tutorial we can simplify the first(I.) case to se
@Autowired
is spring-specific. @Inject
is the standard equivallent. It is an annotation that tells the context (spring, or in the case of @Inject
- any DI framework) to try to set an object into that field.
The compiler has nothing to do with this - it is the DI framework (spring) that instantiates your objects at runtime, and then sets their dependencies at the points you have specified - either via XML or via an annotation.
I agree it is a possible scenario for a DI framework to try to inject dependencies into all fields, even if they are not annotated. (And if you want to exclude a particular field, to annotate it). But they chose the other strategy (configuration-over-convention). By the way: