本文介绍了是什么在Spring框架@Inject和@Autowired之间的区别?哪一个是什么情况下使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过SpringSource的,并在博客作者之一,一些博客中使用 @Inject ,我想他也可以用 @Autowired

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

下面是一块code的:

Here is the piece of code:

@注入私人CustomerOrderService customerOrderService;

我不知道关于 @Inject @Autowired ,并将AP preciate如果之间的区别有人可以解释这种差异,哪一个什么情况下使用?

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

推荐答案

这里假设你指的是<$c$c>javax.inject.Inject注释。 @Inject 是Java CDI的一部分()标准,。春天已经选择使用支持 @Inject 同义词用自己的 @Autowired 注释。

Assuming here you're referring to the javax.inject.Inject annotations. @Inject is part of the Java CDI (Contexts and Dependency Injection) standard introduced in Java EE 6 (JSR-299), read more. Spring has chosen to support using @Inject synonymously with their own @Autowired annotation.

因此​​,要回答你的问题, @Autowired 是Spring自己的(传统)注释。 @Inject 是一个新的Java技术,名为CDI,定义了类似的春天依赖注入一个标准的组成部分。在Spring应用程序,这两个注释的工作原理春天已经决定支持除一些JSR-299注解自己以同样的方式。

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.

这篇关于是什么在Spring框架@Inject和@Autowired之间的区别?哪一个是什么情况下使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 23:12