Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使SpringJMS从注释@JmsListener中选取目标队列名称_Java_Spring_Ibm Mq_Spring Jms - Fatal编程技术网

Java 如何使SpringJMS从注释@JmsListener中选取目标队列名称

Java 如何使SpringJMS从注释@JmsListener中选取目标队列名称,java,spring,ibm-mq,spring-jms,Java,Spring,Ibm Mq,Spring Jms,任何帮助都将不胜感激。我试图用SpringJMSListener创建MDB的替代品。我希望将目标名称作为注释传递,但我注意到,org.springframework.jms.listener.DefaultMessageListenerContainercontainer配置必须使用destinationName或destination。我错过什么了吗?如何使用目标解析器使用@JmsListener注释中的队列名称 @Component public class InitStRspnLstnr

任何帮助都将不胜感激。我试图用SpringJMSListener创建MDB的替代品。我希望将目标名称作为注释传递,但我注意到,
org.springframework.jms.listener.DefaultMessageListenerContainer
container配置必须使用
destinationName
destination
。我错过什么了吗?如何使用目标解析器使用
@JmsListener
注释中的队列名称

@Component 
public class InitStRspnLstnr {

@JmsListener(destination = "${xyz.company.MQ.INITST.RSPN.FADS.Q}")
public void onMessage(Message msg) throws JMSException {
    System.out.println("**********************************************"+msg);
}}
@Component 
public class SampleLstner{     
@JmsListener(concurrency = "1", destination = "${company.project.MQ.module.Q}", containerFactory = "jmsListenerContainerFactory")
           public void onMessage(Message msg) throws JMSException {}
 }
下面是我粘贴的Xml,我现在对容器进行了注释,因为spring试图连接到虚拟队列而不是注释中的队列

        <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:cxf="http://cxf.apache.org/core"    
        xmlns:jaxrs="http://cxf.apache.org/jaxrs"
        xmlns:jaxws="http://cxf.apache.org/jaxws"    
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd  
            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
            http://cxf.apache.org/jaxrs
            http://cxf.apache.org/schemas/jaxrs.xsd
            http://cxf.apache.org/jaxws
            http://cxf.apache.org/schemas/jaxws.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
            ">

        <import resource="classpath*:com/xyz/svc/component.xml"/>

        <mvc:annotation-driven enable-matrix-variables="true"/>
        <context:component-scan base-package="com.xyz.css.rplr.initst"></context:component-scan>

        <!-- WebSphere MQ Connection setup start -->
        <bean id="mqIdsConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
            <property name="hostName"><value>${xyz.company.MQ.HOST.NM}</value></property>
            <property name="port"><value>${xyz.company.MQ.PORT}</value></property>
            <property name="queueManager"><value>${xyz.company.MQ.QMNGR}</value></property>
            <property name="channel"><value>${xyz.company.MQ.CHANNEL}</value></property>
            <property name="CCSID"><value>819</value></property>
            <property name="transportType">
                <util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP" />
            </property>
        </bean>
        <bean id="jmsQueueIdsConnectionFactory"
            class="org.springframework.jms.connection.SingleConnectionFactory">
            <property name="targetConnectionFactory">
                <ref bean="mqIdsConnectionFactory" />
            </property>
        </bean>
        <bean id="jmsDestinationResolver"
            class="org.springframework.jms.support.destination.DynamicDestinationResolver">
        </bean>
        <bean id="jmsQueueIdsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory">
                <ref bean="jmsQueueIdsConnectionFactory" />
            </property>
            <property name="destinationResolver">
                <ref bean="jmsDestinationResolver" />
            </property> <!--    
            <property name="defaultDestinationName">
                <value>${xyz.company.MQ.INITST.Q}</value>
            </property>-->
            <property name="pubSubDomain">
                <value>false</value>
            </property>
            <property name="receiveTimeout">
                <value>20000</value>
            </property>
        </bean>

        <!-- <bean id="jmsContainer"
            class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="connectionFactory">
                <ref bean="jmsQueueIdsConnectionFactory" />
            </property>
            <property name="destinationResolver">
                <ref bean="jmsDestinationResolver" />
            </property>
            <property name="destinationName" value="dummyQueue"/>
            <property name="concurrency" value="3-10" />
        </bean> -->

        <!-- WebSphere MQ Connection setup end -->
    </beans>
@Component 
public class SampleLstner{     
@JmsListener(concurrency = "1", destination = "${company.project.MQ.module.Q}", containerFactory = "jmsListenerContainerFactory")
           public void onMessage(Message msg) throws JMSException {}
 }

${xyz.company.MQ.HOST.NM}
${xyz.company.MQ.PORT}
${xyz.company.MQ.QMNGR}
${xyz.company.MQ.CHANNEL}
819
假的
20000

在下面添加了工作版本。如果通过注释在代码中设置defaultDestinationName,则xml中不需要defaultDestinationName<代码>${company.project.MQ.module.Q}和从属性文件加载的其他值,也可以硬编码

@Component 
public class SampleLstner{     
@JmsListener(concurrency = "1", destination = "${company.project.MQ.module.Q}", containerFactory = "jmsListenerContainerFactory")
           public void onMessage(Message msg) throws JMSException {}
 }
XML

@Component 
public class SampleLstner{     
@JmsListener(concurrency = "1", destination = "${company.project.MQ.module.Q}", containerFactory = "jmsListenerContainerFactory")
           public void onMessage(Message msg) throws JMSException {}
 }

${company.project.MQ.HOST.NM}
${company.project.MQ.PORT}
${company.project.MQ.QMNGR}
${company.project.MQ.CHANNEL}
819
1.
假的
20000

首先要正确配置。您没有任何基于注释的JMS支持。就像解释的那样。让它发挥作用。。。。谢谢你指出这一点。。我已经试过了,却少了一个罐子`@Jugunu您应该发布您自己问题的答案,并详细说明您为解决问题所做的工作,这将比没有格式的评论好得多。@JoshMc:我没有收到您的评论,我将发布工作版本。@saad:我没有这个选择,只需选择添加另一个答案即可!。我也不能把自己推到最前面。有什么建议吗?
@Component 
public class SampleLstner{     
@JmsListener(concurrency = "1", destination = "${company.project.MQ.module.Q}", containerFactory = "jmsListenerContainerFactory")
           public void onMessage(Message msg) throws JMSException {}
 }