如何重用 ejb-jar.xml 部署描述符中的元素?

How to re-use elements in a ejb-jar.xml deployment descriptor?

我目前正在编写一组与一些旧 EJB2 代码交互的 EJB。作为其中的一部分,我有一个 ejb-jar.xml 部署描述符,其中包含会话 bean 的 resource-refs 和 ejb-refs。所有这些定义基本上是相同的——只是会话 bean 的名称不同。显然,这并不理想——每次添加新 bean 时,我都必须复制并粘贴一大块 XML.

结构看起来像这样:

<ejb-jar 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
    <enterprise-beans>
        <session>
            <ejb-name>/* redacted */</ejb-name>

            <resource-ref>
                <res-ref-name>/* redacted */</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Application</res-auth>
                <lookup-name>/* redacted */</lookup-name>
            </resource-ref>

            <ejb-ref>
                <ejb-ref-name>/* redacted */</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <home>/* redacted */</home>
                <remote>/* redacted */</remote>
            </ejb-ref>

            /* about 20 more ejb-refs later... */
        </session>

        /* several near identical session beans here ... */
</ejb-jar>

有没有办法在多个定义中重复使用这些引用而不重复?或者,是否有更好的方法来实现我所缺少的相同最终结果?

在我的特定情况下,我能够通过将 EJB 打包为 WAR 而不是普通 JAR 文件来解决问题 - 这使我能够在 web.xml 中提供参考应用程序作为一个整体,而不是在每个 bean 级别上。