@Autowired
annotation is defined in the Spring framework.
@Inject
annotation is a standard annotation, which is defined in the standard "Dependency Injection for Java" (JSR-330). Spring (since the version 3.0) supports the generalized model of dependency injection which is defined in the standard JSR-330. (Google Guice frameworks and Picocontainer framework also support this model).
With @Inject
can be injected the reference to the implementation of the Provider
interface, which allows injecting the deferred references.
Annotations @Inject
and @Autowired
- is almost complete analogies. As well as @Autowired
annotation, @Inject
annotation can be used for automatic binding properties, methods, and constructors.
In contrast to @Autowired
annotation, @Inject
annotation has no required
attribute. Therefore, if the dependencies will not be found - will be thrown an exception.
There are also differences in the clarifications of the binding properties. If there is ambiguity in the choice of components for the injection the @Named
qualifier should be added. In a similar situation for @Autowired
annotation will be added @Qualifier
qualifier (JSR-330 defines it's own @Qualifier
annotation and via this qualifier annotation @Named
is defined).