【问题标题】:CDI and EJB mix with glassfish 3.1CDI 和 EJB 与 glassfish 3.1 混合
【发布时间】:2014-10-07 10:06:23
【问题描述】:

我在 glassfish 上部署了两个应用程序 - 应用程序 A 和 B。

两者都部署为war包,应用程序B使用应用程序A的一些组件。

现在在应用程序 A 中我有一个接口:

public interface BusinessInterface() extends SomeOtherInterface {
    void someAction();
}

我有这个接口的 3 个实现 - 两个在应用程序 A 中,一个在应用程序 B 中:BusinessInterfaceA1, BusinessInterfaceA2, BusinessInterfaceB

只要它们都是 CDIBean,一切都很好 - 我使用自定义 @Qualifier 注释(@BusinessInterfaceA1、@BusinessInterfaceA2)和 B 的实现的 @Default 注释来区分它们。

但是现在我需要两个应用程序的 A 实现都是有状态的 EJB,这就是它变得有趣的地方。

当我在两个实现上添加 @Statefull 注释时,我得到了这样的结果:

javax.servlet.ServletException: org.jboss.weld.exceptions.WeldException: WELD-000049

详情:

java.lang.IllegalStateException: Unable to convert ejbRef for ejb BusinessInterfaceA1 to a business object of type interface SomeOtherInterface

我该如何解决?我需要所有实现都以一种我可以注入它们的方式可用,就像

@Inject @SomeAnnotation private BusinessInterface businessInterface;

【问题讨论】:

    标签: java dependency-injection ejb cdi glassfish-3


    【解决方案1】:

    在 Glassfish 3.1 中是 bug。解决方法是,用所有必需的接口标记实现,例如:

    @Statefull/@Stateless
    public class BusinessInterfaceImpl implements BusinessInterface, SomeOtherInterface {
       // implementation
    }
    

    即使 BusinessInterface 扩展了 SomeOtherInterface,从 Java 规范来看,这样做也没用,但作为该错误的解决方法,它可以工作。

    另一种解决方案是使用 Glassfish 4.0

    【讨论】:

    • 好久没用了,暂时没有合适的环境测试,不过还是谢谢了。
    猜你喜欢
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多