【问题标题】:Stateless EJB implements interface injection failed无状态 EJB 实现接口注入失败
【发布时间】:2015-12-18 10:02:16
【问题描述】:

野蝇 8.2.0

我有一个Stateless EJB 和一个接口。

@Local
@Stateless
public class Bean implements IBean{
...
}

@Local
public interface IBean {
...
}

但我得到一个焊接错误。如果 Bean 没有实现接口,则没有错误。根据https://stackoverflow.com/a/13988450/2023524 和https://blogs.oracle.com/arungupta/entry/what_s_new_in_ejb 应该没有错误。

错误:

WELD-001408: Unsatisfied dependencies for type Bean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private mypackage.anotherBean.bean

更新: 我用Local 尝试了所有可能的组合,但没有帮助。只有当接口被删除时,才没有错误。

@Stateless
public class Bean implements IBean{
...
}

@Local
public interface IBean {
...
}

//*****************************
@Stateless
public class Bean implements IBean{
...
}

public interface IBean {
...
}
//************************************
@Local
@Stateless
public class Bean implements IBean{
...
}

public interface IBean {
...
}

【问题讨论】:

    标签: java ejb wildfly-8 weld


    【解决方案1】:

    当您想通过 EJB(使用 @EJB)或 CDI(使用 @Inject)容器注入 bean 时,您声明一个具有接口类型的变量。声明接口的具体实现由容器在应用程序部署期间找到。在您的示例中,问题不在于注释,而在于注入了声明的类型(Bean 而不是IBean)。

    【讨论】:

      【解决方案2】:

      您需要从 Bean 中删除 @Local。

      @Stateless
      public class Bean implements IBean{
      ...
      }
      

      因为您定义了 2 个可能的 Local WELD 不知道使用哪一个。

      oracle 文档也通过@Remote 接口显示了这一点:

      @Remote
      public interface Foo { . . . }
      
      @Stateless
      public class Bean implements Foo, Bar {
          . . .
      }
      

      【讨论】:

      • 感谢您的回答。但这无济于事。查看问题更新。
      猜你喜欢
      • 2012-08-26
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      • 2017-10-26
      • 1970-01-01
      相关资源
      最近更新 更多