通过替换HornetQ添加ActiveMQ时服务器启动时出错

时间:2019-03-06 10:44:14

标签: spring rest activemq

我正在使用REST API使用Spring 4,Hibernate和ActiveMQ

enter image description here

ActiveMQ配置

<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    <property name="connectionFactory" ref="connectionFactory"></property>
</bean>

<!-- Configuration for Publishing Jms Messages -->
<bean id="activeMqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616"/>
    <property name="disableTimeStampsByDefault" value="true"/>
    <property name="useAsyncSend" value="true"/>
    <property name="nonBlockingRedelivery" value="true"/>
    <property name="redeliveryPolicy" ref="redeliveryPolicy"/>
</bean>

<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
    <property name="initialRedeliveryDelay" value="60000"/>
    <property name="backOffMultiplier" value="3"/>
    <property name="maximumRedeliveryDelay" value="60000"/>
    <property name="maximumRedeliveries" value="3"/>
    <property name="redeliveryDelay" value="60000"/>
    <property name="useExponentialBackOff" value="true"/>
</bean>

<!--<bean id="outgoingSmsQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <property name="physicalName" value="queue/outgoingSmsQueue"/>
</bean>
<bean id="emailServiceQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <property name="physicalName" value="queue/emailServiceQueue"/>
</bean>-->

<bean id="activemqOrderQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <property name="physicalName" value="ActiveMQ.orderQueue"/>
</bean>
<bean id="activemqDLQ" class="org.apache.activemq.command.ActiveMQQueue">
    <property name="physicalName" value="ActiveMQ.DLQ"/>
</bean>

<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="activeMqConnectionFactory"/>
    <property name="sessionCacheSize" value="200"/>
    <property name="cacheProducers" value="true"/>
    <property name="cacheConsumers" value="true"/>
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="sessionTransacted" value="true"/>
    <property name="deliveryPersistent" value="true"/>
    <property name="explicitQosEnabled" value="true"/>
    <property name="messageIdEnabled" value="false"/>
    <property name="messageTimestampEnabled" value="false"/>
</bean>


<bean id="jmsProducer" class="com.mahopos.jms.JmsProducerImpl">
    <property name="jmsTemplate" ref="jmsTemplate"/>
</bean>


<!-- End Configuration for Publishing Jms Messages -->

<bean id="dlqMessageListener" class="com.mahopos.jms.DlqMessageListener" autowire="byName">
</bean>

<bean id="dlqMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
      parent="baseMessageListenerContainer">
    <property name="destination" ref="activemqDLQ"/>
    <property name="messageListener" ref="dlqMessageListener"/>
</bean>


<bean id="baseMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
      abstract="true">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="transactionManager" ref="jmsTransactionManager"/>
    <property name="concurrentConsumers" value="10"/>
    <property name="maxConcurrentConsumers" value="10"/>
    <property name="idleConsumerLimit" value="1"/>
    <property name="receiveTimeout" value="5000"/>
    <property name="idleTaskExecutionLimit" value="50"/>
    <property name="cacheLevel">
        <util:constant
                static-field="org.springframework.jms.listener.DefaultMessageListenerContainer.CACHE_CONSUMER"/>
    </property>
</bean>


<bean id="orderQueueListener" class="com.mahopos.jms.OrderQueueListener">
    <property name="demoApiService" ref="demoApiService"/>
    <property name="delay" value="1500"/>
</bean>

<bean id="orderQueueListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"
      parent="baseMessageListenerContainer">
    <property name="concurrentConsumers" value="5"/>
    <property name="destination" ref="activemqOrderQueue"/>
    <property name="messageListener" ref="orderQueueListener"/>
    <property name="sessionTransacted" value="true"/>
</bean>

显然,似乎ContextLoaderListener初始化了多次,但是在哪里?

服务器成功运行,但附加的图片显示在Chrome(浏览器)中,并且服务器启动后未运行REST调用。

1 个答案:

答案 0 :(得分:0)

@justin Bertram,HornetQ以前在工作,我用Activemq代替了它,该应用程序基于REST。 通过添加替换

中的依赖关系来解决问题
<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.2.5.RELEASE</version>
    </dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.3.22.RELEASE</version>
    </dependency>

问题似乎是由于库冲突