ActiveMQ集成到spring

本文介绍了如何将ActiveMQ集成到Spring中,包括解决版本冲突问题,只引入必要的依赖如spring-jms和activemq-client。配置spring-activemq.xml文件后,详细讲解了Sender和Receiver的编写,Receiver部分涵盖了同步接收和异步监听接收两种方式,异步接收通过实现MessageListener接口来实现。
摘要由CSDN通过智能技术生成

spring集成activemq

1、maven引入spring-jms和activemq-client(注意版本兼容的问题)

<properties>
    <spring.version>4.3.4.RELEASE</spring.version>
    <activemq.version>5.14.0</activemq.version>
</properties>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-client</artifactId>
    <version>${activemq.version}</version>
</dependency>

小插曲:一开始我引入activemq-all,导致启动报错

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;] with root cause

这是因为跟spring-core版本冲突了,其实没必要引入activemq-all,只要activemq-cilent就够了

最终maven会下载5个jar包
spring-jms-4.3.4.RELEASE-sources.jar
activemq-client-5.14.0.jar
geronimo-jms_1.1_spec-1.1.1.jar
hawtbuf-1.11.jar
geronimo-j2ee-management_1.1._spec-1.0.1.jar

2、配置spring-avtivemq.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值