ActiveMQ学习之路 (二)spring实现

    技术2022-07-11  88

    ActiveMQ Topic的实现

    maven配置xml

    <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.8.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>5.2.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.6.RELEASE</version> </dependency>

    出现错误

    Caused by: org.springframework.beans.FatalBeanException: Could not find NamespaceHandler class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] for namespace [http://activemq.apache.org/schema/core]; nested exception is java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler

    出现该问题是在处理activemq和spring集成时出的问题。添加依赖 xbean-spring。 XBean是Apache Geronimo的子项目,设计这个的目的是为了能为Geronimo的插件提供一种方便 快捷的配置方式(具体怎么方便快捷,看完全文便知)。后来,Xbean被更多的开源项目引用。例如:jetty、Activemq等等,同时xbean也提供了对spring的支持。

    <dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> <version>3.16</version> </dependency> <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>xstream</artifactId> <version>1.3.1</version> </dependency>

    再次出现问题

    java.lang.ClassNotFoundException: javax.jms.JMSContext

    这个版本的Spring需要使用JMS 2.0版本,但spring-jms的依赖没有自动导入JMS 2.0,而activemq-core会导入JMS 1.1的依赖,这就导致出现版本问题 添加一下依赖解决,JMS 2.0 依赖

    <dependency> <groupId>javax.jms</groupId> <artifactId>javax.jms-api</artifactId> <version>2.0.1</version> </dependency>

    终于执行成功了

    Processed: 0.009, SQL: 9