我正在尝试使用ejb2和solace Resource adapter将solace与web sphere liberty 20版本集成。我已经在侦听队列的ejb中配置了MDB bean。我能够获得MDB上的消息,但在处理过程中,我需要将响应发布回一个队列,并且此队列名称是基于来自上游系统的消息的动态名称。所以我不能将发布者配置为容器中的无状态bean。
现在,我想在发布者代码中使用连接工厂,它是使用solace资源适配器在server.xml中为MDB配置的。
我已经尝试了以下方法。
在server.xml中:
<featureManager>
<feature>javaee-8.0</feature>
<feature>localConnector-1.0</feature>
<feature>jndi-1.0</feature>
<feature>wasJmsClient-2.0</feature>
<feature>wasJmsServer-1.0</feature>
<feature>wasJmsSecurity-1.0</feature>
<feature>mdb-3.2</feature>
<feature>servlet-4.0</feature>
<feature>ejb-3.2</feature>
<feature>ejbHome-3.2</feature>
<feature>adminCenter-1.0</feature>
<feature>jca-1.7</feature>
<feature>jms-2.0</feature>
<feature>webProfile-8.0</feature>
<resourceAdapter autoStart="true" id="solace" location="sol-jms-ra-10.10.0.rar">
<properties.solace ConnectionURL="URL" UserName="user1" Password="pwd" MessageVPN="TEST_VPN"/>
</resourceAdapter>
<jmsActivationSpec id="JNDI/LISTENER">
<properties.solace connectionFactoryJndiName="myCF" destination="queue" destinationType="javax.jms.Queue" />
</jmsActivationSpec >
<jmsConnectionFactory id="JNDI/J2C/CF" jndiName="JNDI/J2C/CF">
<properties.solace ConnectionFactoryJndiName="myCF"/>
</jmsConnectionFactory>在我的发布者代码中,执行jndi查找,如下所示。
Context ctx = new InitialContext();
connectionFactory = (QueueConnectionFactory) ctx.lookup("java:comp/env/JNDI/J2C/CF");
connection = connectionFactory.createQueueConnection();但是得到下面的异常
javax.naming.NameNotFoundException: javax.naming.NameNotFoundException: java:comp/env/JNDI/J2C/CF
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:355)
at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:370)
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:149)
at javax.naming.InitialContext.lookup(InitialContext.java:417)有没有人能帮帮我。
发布于 2021-02-11 00:55:23
您需要定义一个从资源引用名称java:comp/env/JNDI/J2C/CF到配置的jndiName JNDI/J2C/CF的绑定。
要做到这一点,一种标准方法是在web或希望查找它的组件中使用@Resource注释(您也可以使用由@Resource注释注入的值,而不是查找)。例如,
@Resource(name = "java:comp/env/JNDI/J2C/CF", lookup = "JNDI/J2C/CF")
QueueConnectionFactory qcf;您可以使用的另一种方法是在ejb-jar.xml文件中定义资源引用。例如,
<ejb-jar 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"
version="2.1">
<enterprise-beans>
<message-driven>
<ejb-name>MyMessageDrivenBean</ejb-name>
<ejb-class>org.example.MyMessageDrivenBean</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>java:comp/env/JNDI/J2C/CF</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
<lookup-name>JNDI/J2C/CF</lookup-name>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>或者
<ejb-jar 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"
version="2.1">
<enterprise-beans>
<session>
<ejb-name>MyStatelessBean</ejb-name>
<ejb-class>org.example.MyStatelessBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>java:comp/env/JNDI/J2C/CF</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
<lookup-name>JNDI/J2C/CF</lookup-name>
</resource-ref>
</session>
</enterprise-beans>
</ejb-jar>另外,假设您想要一个配置,那么您需要使用jmsQueueConnectionFactory配置元素,
<jmsQueueConnectionFactory id="JNDI/J2C/CF" jndiName="JNDI/J2C/CF">
<properties.solace ConnectionFactoryJndiName="myCF"/>
</jmsQueueConnectionFactory>https://stackoverflow.com/questions/66141135
复制相似问题