如何使用ejb home / remote的global-module类?

问题描述 投票:0回答:1

将现有项目迁移到maven和wildfly,并且必须移动一些文件以创建以下情况。

  • core.jar添加
  • ejb1.jar
  • Ejaba2yara

使用ejb1.jar的ejb-jar.xml具有以下内容:

<ejb-jar>
  <enterprise-beans>
    <session id="Value">
      ..
      <home>path.to.ejb1Home</home>
      <remote>path.to.ejb1</remote>
      ...

home和remote标签中引用的类已移至core.jar中

同时,ejb2.jar依赖于core.jar的其他部分。

看起来最简单的解决方案是创建一个全局模块并在其中放置core.jar,在standalone.sh中创建相应的module.xml和条目,以使所有部署都可以访问它。

module.xml

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.0" name="path.to"> 
  <resources> 
    <resource-root path="core-1.0.jar"/>
  </resources> 
  <dependencies> 
  </dependencies> 
</module>

使用此设置,ejb2.jar按预期部署,但ejb1.jar会引发以下错误:

Caused by: java.lang.NoClassDefFoundError: Failed to link path.to.ejb1 
    (Module "path.to" from local module loader @4c40b76e (finder: local 
     module finder @2ea6137 (roots: /opt/wildfly/modules, 
     /opt/wildfly/modules/system/layers/base))): javax/ejb/EJBObject
java maven ejb wildfly maven-3
1个回答
0
投票

你应该仔细考虑你的要求。通常,您不需要提供公共资源(尤其是应用程序接口)作为模块,尤其是作为全局模块。根据您的要求选择合适的解决方案,而不是在不知道其含义的情况下一眼就能看到的解决方案。

我会按照给出的顺序推荐这些可能性(有关更多信息,请参阅Class Loading in Wildfly Documentation):

  1. 重新考虑您对不同EAR的要求。使用您的EAR将核心jar作为库提供。
  2. 即使有多个EAR:提供core.jar作为库。这不是冗余,这只是分离。
  3. 考虑不使用全局模块。只需安装自定义模块即可。提供jboss-deployment-structure.xml文件,将此模块添加为附加依赖项。如果模块包含已注释的类或接口(应在部署时考虑),请使用模块依赖关系配置设置属性annotations=true
  4. 将全局模块添加到配置文件中。可能你甚至可以使用'annotations'属性,但这是我不知道的,我没有检查。

jboss-deployment-structure.xml文件的示例:

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
      <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
      <deployment>
        <dependencies>
          <module name="my.custom.module" export="true" annotations="true"/>
        </dependencies>
      </deployment>
    </jboss-deployment-structure>

编辑:

安装模块时,不要忘记为您自己的模块所依赖的其他模块提供传递模块依赖性。使用您的module.xml文件来执行此操作。在您的情况下,您可能至少需要依赖javax.ejb.api模块。

© www.soinside.com 2019 - 2024. All rights reserved.