简体   繁体   English

spring3 @autowired和@inject

[英]spring3 @autowired and @inject

i'm spring2.5, i normally use @autowired for DI. 我是spring2.5,我通常使用@autowired进行DI。 If i not wrong, in spring3, we can use @Inject for similar feature right? 如果我没看错,在spring3中,我们可以使用@Inject来实现类似功能,对吗? please comment. 请评论。 I tried to add @Inject instead of @autowired but doesnt work. 我试图添加@Inject而不是@autowired,但是不起作用。 need extra library? 需要额外的图书馆吗?

If by "doesn't work" you mean that the annotation can't be resolved, then yes, you need a JSR-330 API library. 如果“不起作用”表示无法解析注释,那么是的,您需要JSR-330 API库。 You can download it here . 您可以在这里下载。

Or if you use maven: 或者,如果您使用Maven:

<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM