【问题标题】:Injecting one ejb bean inside another within the same jar module not working在同一个 jar 模块中将一个 ejb bean 注入另一个 ejb bean 不起作用
【发布时间】:2020-01-30 13:16:27
【问题描述】:

我的 jar 模块中有两个 bean -> 豆A:

@Singleton
public final class A {
    public String getS() {
        return"";
}

和同一个 jar 模块中的第二个 bean B:

@Stateless
public final class B {
    @Inject
    private A a;

    public String getAS() {
        a.getS() // -> NullPointerException
    }
}

我在

中有文件 beans.xml
src/main/resources/META-INF/
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>

添加到 pom.xml 中,但仍然注入的 A 为空。

在生成的 jar 文件中存在 beans.xml

我是否错过了什么?

【问题讨论】:

  • 你看到罐子里的 beans.xml 了吗?
  • @Laertes 实际上我并没有在我的 jar 文件中看到 beans.xml,这可能是什么原因?
  • @Kukeltje javaee api被提供,B类是无状态ejb bean
  • 好的,我添加了这个细节

标签: jboss ejb cdi weld


【解决方案1】:

使用 maven 构建 jars 的 beans.xml 的默认位置是

src/main/resources/META-INF/

【讨论】:

  • 这就是我拥有 beans.xml 的地方
  • 如果路径是 src\main\resources\META-INF\beans.xml Maven 会自动将其放在 jar 中正确的位置。你可以仔细检查一下...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 2011-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多