当前位置:   article > 正文

spring 集成rabbitmq 遇到的问题:版本配置_spring-rabbit版本选择

spring-rabbit版本选择

版本配置时,遇到了一个小问题,记录一下;

  1. pom.xml配置文件中,依赖的组件比较旧了,需要更新;
  2. <!--消息队列-->
  3. <dependency>
  4. <groupId>com.rabbitmq</groupId>
  5. <artifactId>amqp-client</artifactId>
  6. <version>3.5.1</version>
  7. </dependency>
  8. <dependency>
  9. <groupId>org.springframework.amqp</groupId>
  10. <artifactId>spring-rabbit</artifactId>
  11. <version>1.4.5.RELEASE</version>
  12. </dependency>

更新到新版本

  1. <dependency>
  2. <groupId>com.rabbitmq</groupId>
  3. <artifactId>amqp-client</artifactId>
  4. <version>5.6.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.amqp</groupId>
  8. <artifactId>spring-rabbit</artifactId>
  9. <version>2.1.4.RELEASE</version>
  10. </dependency>

 

1、spring-rabbit组件 依赖 amqp-client组件,并且,之间的版本号,也要匹配好,不然,运行时就会出错;

https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit/1.4.5.RELEASE

https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit/2.1.4.RELEASE

 

2、application-context.xml文件中,rabbit组件版本修改后,xsd文件配置spring rabbit相关对象,引用的xsd定义文件,也要匹配;

旧的写法,指定了 spring-rabbit-1.0.xsd 特定版本的xml schema文件,不匹配 spring-rabbit 2.1.4.RELEASE 版本

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:rabbit="http://www.springframework.org/schema/rabbit"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/rabbit
  8. http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
  9. <!-- 连接配置 -->
  10. <rabbit:connection-factory id="connectionFactory" host="${mq.host}" username="${mq.username}"
  11. password="${mq.password}" port="${mq.port}" />
  12. <rabbit:admin connection-factory="connectionFactory" />

修改后,去掉版本号后缀;

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:rabbit="http://www.springframework.org/schema/rabbit"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/rabbit
  8. http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
  9. <!-- 连接配置 -->
  10. <rabbit:connection-factory id="rabbitConnectionFactory" host="${mq.host}" username="${mq.username}"
  11. password="${mq.password}" port="${mq.port}" />
  12. <rabbit:admin connection-factory="rabbitConnectionFactory" />
在IDEA中,点击 rabbit:connection-factory 标签,会跳转该标签所在jar包的xsd定义文件中;

==》修改成 spring-rabbit.xsd 后,应该是优先到jar包中找对应的xsd定义文件吧;

     (TODO 有空要确认下spring在这方面的机制)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/956437
推荐阅读
相关标签
  

闽ICP备14008679号