javax.inject.Inject不起作用 [英] javax.inject.Inject does not work

查看:137
本文介绍了javax.inject.Inject不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们进行了一些Maven pom.xml清理,并且依赖项注入停止工作.例如,这曾经可以工作,但不再起作用:

In our project we did some Maven pom.xml cleanup and dependency injection stopped working. For example, this used to work but works no longer:

@Inject
private ItemService itemService;

public void whatever() {
    itemService.whatever();
}

当我们运行 whatever()时, itemService 为null,日志中没有错误/警告消息.只有一个bean实现了该接口:

The itemService is null when we run whatever(), no error/warning message present in log. There's only one bean implementing the interface:

public interface ItemService { ... }

@ContainerManaged
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ItemServiceBean implements ItemService { ... }

我们尝试将所有依赖项放回发生此错误的项目中,但这无济于事.我不知道从哪里开始寻找.以下任何一项都将有所帮助:

We tried putting all the dependencies back in the project where this error occurs, but that didn't help. I don't know where to start looking. Any of these would be helpful:

  • 在哪里使用@Inject?在运行时,是Spring吗?是否有一些源代码会有所帮助?也许那个代码的罐子是我们所缺少的?
  • 是否有某种方法可以在日志中打印一些提示?当然,更好的是在编译时出现一些错误,但这很可能使我很不高兴...
  • 当然,如果您知道我们所缺少的依赖项,那将是最好的选择.:)我们正在运行Spring,OpenJPA等,但是不知道与列表相关的内容.如果您知道要问什么,我会尽力找到答案.

推荐答案

在pom.xml中包括以下依赖项

Include the following dependency in your pom.xml

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

这篇关于javax.inject.Inject不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆