【问题标题】:EJB Dependency Injection works with EAR but not JAREJB 依赖注入适用于 EAR,但不适用于 JAR
【发布时间】:2012-07-05 13:52:17
【问题描述】:

环境

  • 两个具有远程接口的无状态 EJB。 EJB1 被注入到 EJB2 中。
    /// EJB1

    package com.xxx.layer1;

    @Remote
    public interface EJB1Remote {
    }

    @Stateless (mappedNamed="com.xxx.EJB1")
    public class EJB1 implements EJB1Remote {
    }


    /// EJB2

    package com.xxx.layer2;

    import com.xxx.layer1;

    @Remote
    public interface EJB2Remote {
    }

    @Stateless (mappedNamed="com.xxx.EJB2")
    public class EJB2 implements EJB2Remote {

        @EJB(mappedNamed="com.xxx.EJB1")
        EJB1Remote ejb1;
    }
  • EJB2 还使用一些可选包(在其 MANIFEST 中声明)

  • WebLogic 应用服务器 (10.3.3)

  • 两个 EJB 被打包到两个单独的 JAR 文件中

问题

如果将两个 JAR 文件打包到一个 EAR 文件中并进行部署,则依赖注入有效。但是如果我单独部署它们,即使在我首先部署了 EJB1 并在 Weblogic 中验证了全局 JNDI 名称之后 (com.xxx.EJB1#com.xxx.layer1.EJB1Remote ),EJB2 的部署失败并出现 ClassNotFoundException: com.xxx.layer1.EJB1Remote

【问题讨论】:

    标签: java dependency-injection ejb weblogic-10.x


    【解决方案1】:

    在这种情况下,每个单独的 JAR 文件都是 WebLogic 中自己的应用程序,每个应用程序都有自己的类加载器。因此,当 JAR 文件单独部署(未捆绑在 EAR 文件中)时,它们的类加载器不会看到其他类中的类。

    在这种情况下,我将 EJB2 的接口分离到另一个 JAR 文件中,并将其部署为可选包,并将其引用添加到其他 JAR 文件的清单中。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2012-12-31
      • 1970-01-01
      • 2017-06-16
      • 2019-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多