You need to enable JavaScript to run this app. 基于EJB 2.x的WebSphere Liberty集成Solace资源适配器配置咨询
优惠活动
大模型
产品
解决方案
定价
更多

基于EJB 2.x的WebSphere Liberty集成Solace资源适配器配置咨询

WebSphere Liberty 环境下EJB 2.x 对接Solace资源适配器的配置方案

整套配置无需依赖EJB 3.x的注解式资源引用逻辑,Liberty对EJB 2.x对应的老式J2EE描述符、xmi格式绑定文件存在完整向后兼容支持,三个核心文件的配置规则如下:

1. server.xml(Liberty 服务端配置)

需提前将适配JCA 1.5+规范的Solace RAR包放置到Liberty的sharedResource目录下,启用对应运行特性并完成资源适配器、JNDI资源的全局定义:

<featureManager>
    <!-- 启用必备运行特性,Enterprise Beans 3.2特性向下兼容EJB 2.x规范 -->
    <feature>jca-1.7</feature>
    <feature>enterpriseBeans-3.2</feature>
    <feature>messaging-3.0</feature>
</featureManager>

<!-- 定义Solace资源适配器 -->
<resourceAdapter id="solaceRAR" location="${shared.resource.dir}/solace-jca-ra-<实际版本号>.rar">
    <properties.solace
        host="smf://<SolaceBroker地址>:<SMF端口>"
        username="<消息服务账号>"
        password="<对应账号密码>"
        vpnMessageVpnName="<Solace消息VPN名称>"/>
    <connectionManager id="solacePoolCM" maxPoolSize="10" minPoolSize="2"/>
</resourceAdapter>

<!-- 定义全局JNDI绑定的Solace连接工厂 -->
<connectionFactory id="solaceCF" jndiName="jms/SolaceCF">
    <connectionManagerRef ref="solacePoolCM"/>
    <resourceAdapterRef ref="solaceRAR"/>
</connectionFactory>

<!-- 定义全局JNDI绑定的Solace目标队列 -->
<queue id="solaceTestQueue" jndiName="jms/SolaceQueue">
    <resourceAdapterRef ref="solaceRAR"/>
    <properties.solace queueName="<实际Solace队列名>"/>
</queue>

*注意:所有资源适配器的属性名需和Solace RAR提供的可配置参数完全匹配,不要混用EJB 3.x场景下的局部资源引用定义,统一走全局JNDI路径供EJB 2.x Bean查找。

2. ejb-jar.xml(应用侧EJB 2.x标准描述符)

严格遵循EJB 2.1规范格式编写,所有资源引用、Bean属性都需在该文件中显式声明,EJB 2.x运行时会直接读取该配置,不会识别代码中的注解内容:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
    <enterprise-beans>
        <!-- EJB 2.x 规范的消息驱动Bean配置 -->
        <message-driven>
            <ejb-name>SolaceEventListenerMDB</ejb-name>
            <ejb-class>com.example.ejb2.SolaceMessageDrivenBean</ejb-class>
            <transaction-type>Container</transaction-type>
            <message-driven-destination>
                <destination-type>javax.jms.Queue</destination-type>
            </message-driven-destination>

            <!-- 声明对Solace连接工厂的资源引用 -->
            <resource-ref>
                <res-ref-name>jms/SolaceCF</res-ref-name>
                <res-type>javax.jms.QueueConnectionFactory</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>

            <!-- 声明对Solace目标队列的环境资源引用 -->
            <resource-env-ref>
                <resource-env-ref-name>jms/SolaceQueue</resource-env-ref-name>
                <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
            </resource-env-ref>
        </message-driven>
    </enterprise-beans>

    <assembly-descriptor>
        <!-- 配置容器管理事务规则 -->
        <container-transaction>
            <method>
                <ejb-name>SolaceEventListenerMDB</ejb-name>
                <method-name>onMessage</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
    </assembly-descriptor>
</ejb-jar>

*注意:不要在该配置文件中使用EJB 3.x新增的元素格式,所有引用名称需和后续绑定文件的配置完全一致。

3. ibm-ejb-jar-bnd.xmi(WebSphere 专属绑定描述符)

WebSphere Liberty 对EJB 2.x场景下使用的xmi格式绑定文件提供兼容支持,无需替换为EJB 3.x常用的xml格式绑定文件,配置内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<ejb:EJBJar xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
    xmlns:ejb="http://java.sun.com/xml/ns/j2ee"
    xmlns:com.ibm.ejs.jar="http://www.ibm.com/websphere/appserver/schemas/5.0/ejb-jar.xmi"
>
    <ejbJar href="ejb-jar.xml#ejb-jar_ID"/>
    <enterprise-beans>
        <message-driven xmi:id="MessageDriven_1" name="SolaceEventListenerMDB">
            <ejbClassName>com.example.ejb2.SolaceMessageDrivenBean</ejbClassName>
            <jndiName>ejb/SolaceEventListenerHome</jndiName>
            <!-- 绑定连接工厂引用到server.xml定义的全局JNDI路径 -->
            <resourceRefs>
                <res-ref-name>jms/SolaceCF</res-ref-name>
                <jndi-name>jms/SolaceCF</jndi-name>
            </resourceRefs>
            <!-- 绑定队列引用到server.xml定义的全局JNDI路径 -->
            <resourceEnvRefs>
                <resource-env-ref-name>jms/SolaceQueue</resource-env-ref-name>
                <jndi-name>jms/SolaceQueue</jndi-name>
            </resourceEnvRefs>
            <connectionFactoryJndiName>jms/SolaceCF</connectionFactoryJndiName>
            <destinationJndiName>jms/SolaceQueue</destinationJndiName>
        </message-driven>
    </enterprise-beans>
</ejb:EJBJar>

常见踩坑校验点

  • EJB 2.x Bean加载时会优先读取ejb-jar.xml中的显式配置,代码中添加的EJB 3.x风格资源注解会被运行时忽略,不会生效
  • 需保证Solace RAR的版本兼容JCA 1.7规范,过低版本的RAR会出现类加载、连接池初始化失败的问题
  • MDB启动异常时,优先排查server.xml中Solace Broker的连通性、账号权限配置,再校验所有JNDI路径的一致性,排除路径不匹配导致的资源查找失败

内容的提问来源于stack exchange,提问作者Sachin Tomar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.06 19:36:02