What is the difference between @Inject and @Autowired in Spring Framework? Which one to use under what condition?

Technology CommunityCategory: SpringWhat is the difference between @Inject and @Autowired in Spring Framework? Which one to use under what condition?
VietMX Staff asked 3 years ago

@Inject is part of the Java CDI (Contexts and Dependency Injection) standard introduced in Java EE 6 (JSR-299). Spring has chosen to support using @Inject synonymously with their own @Autowired annotation.

So, to answer your question, @Autowired is Spring’s own (legacy) 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 works the same way as Spring has decided to support some JSR-299 annotations in addition to their own.