The annotation @Autowired is springs own annotation. @Inject is part of a new Java technology called CDI that defines a standard for dependency injection similar to Spring. In a spring application, the two annotations work in the same way as Spring has decided to support some JSR-330 annotations in addition to their own.
Both of these annotations use the ‘AutowiredAnnotationBeanPostProcessor’ to inject dependencies.
To add this functionality to you project, add the following to your pom.xml:
Once the jar is on your classpath you can then leverage the functionality like so:
There are some limitations on JSR-330 if you compare it to Spring’s counterpart:
@Inject has no “required” attribute to make sure the bean is injected successful.
In Spring container, JSR-330 has scope singleton by default, but you can use Spring’s @Scope to define others.
No equivalent to Spring’s @Value, @Required or @Lazy.