0 votes
1 view
in Java by (3.4k points)
I am going through some blogs on SpringSource and in one of the blogs, the Sauthor 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 (46.1k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...