Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.4k points)

I am going through some blogs on SpringSource and in one of the blogs, the author is using @Inject and I suppose he can also use @Autowired.

Here is the piece of code:

@Inject private CustomerOrderService customerOrderService;

I am not sure about the difference between @Inject and @Autowired and would appreciate it if someone explained their difference and which one to use under what situation?

1 Answer

0 votes
by (46k points)

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

@Autowired is Spring's own (legacy) explanation. @Inject is part of a new Java technology called CDI that defines a standard for dependency injection related to Spring. In a Spring application, the two annotations work the same way as Spring has chosen to support some JSR-299 explanations in addition to their own.

Browse Categories

...