首先,我有一个关于如何配置 JMS MQ 以在代理连接关闭并重新启动时重新连接到应用程序的问题。
以下是我尝试过的,
这是我最初在 spring-mq-jms-connections.xml 中的配置
<!-- Spring JMS Queue Connection Factory -->
<!--
<bean id="jmsQueueConnectionFactory.7"
class="org.springframework.jms.connection.SingleConnectionFactory" >
<property name="targetConnectionFactory">
<ref bean="internalJmsQueueConnectionFactory.7"/>
</property>
</bean> -->
我用下面的配置替换了它,引入了“DefaultMessageListenerContainer”,它将包装“SingleConnectionFactory”。
<bean id="jmsQueueConnectionFactory.7" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory">
<ref bean="single.connection.factory.7"/>
</property>
<property name="recoveryInterval" value="5000"/>
</bean>
<bean id="single.connection.factory.7" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<ref bean="internalJmsQueueConnectionFactory.7"/>
</property>
</bean>
但是在此配置更改后,我开始收到以下异常。
Failed to configure emapi:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'senderAgent.7' defined in URL
[file://localhost/home/qos/qosdata/config/general/emapi/spring-mq-jms-connections.xml]:
Cannot resolve reference to bean 'jmsQueueTemplate.7' while setting bean property 'jmsTemplate';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'jmsQueueTemplate.7' defined in URL
[file://localhost/home/qos/qosdata/config/general/emapi/spring-mq-jms-connections.xml]:
Cannot resolve reference to bean 'jmsQueueConnectionFactory.7' while setting bean property 'connectionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'jmsQueueConnectionFactory.7' defined in URL [file://localhost/home/qos/qosdata/config/general/emapi/spring-mq-jms-connections.xml]:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
Property 'destination' or 'destinationName' is required
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
它说'destination'或'destinationName'是必需的,我正在处理遗留代码,不知道在哪里寻找这个或者当我更改配置时我正在做正确的事情。
当代理连接因异常或重新启动而中断时,请建议是否有更好的方法将 OpenMQ 与应用程序重新连接。我还查看了带有异常侦听器的 spring jms 连接工厂,但无法弄清楚。