赞
踩
版本配置时,遇到了一个小问题,记录一下;
- pom.xml配置文件中,依赖的组件比较旧了,需要更新;
- <!--消息队列-->
- <dependency>
- <groupId>com.rabbitmq</groupId>
- <artifactId>amqp-client</artifactId>
- <version>3.5.1</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.amqp</groupId>
- <artifactId>spring-rabbit</artifactId>
- <version>1.4.5.RELEASE</version>
- </dependency>
更新到新版本
- <dependency>
- <groupId>com.rabbitmq</groupId>
- <artifactId>amqp-client</artifactId>
- <version>5.6.0</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.amqp</groupId>
- <artifactId>spring-rabbit</artifactId>
- <version>2.1.4.RELEASE</version>
- </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 版本
;
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:rabbit="http://www.springframework.org/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/rabbit
- http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
-
- <!-- 连接配置 -->
- <rabbit:connection-factory id="connectionFactory" host="${mq.host}" username="${mq.username}"
- password="${mq.password}" port="${mq.port}" />
-
- <rabbit:admin connection-factory="connectionFactory" />
修改后,去掉版本号后缀;
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:rabbit="http://www.springframework.org/schema/rabbit"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/rabbit
- http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
-
- <!-- 连接配置 -->
- <rabbit:connection-factory id="rabbitConnectionFactory" host="${mq.host}" username="${mq.username}"
- password="${mq.password}" port="${mq.port}" />
-
- <rabbit:admin connection-factory="rabbitConnectionFactory" />
在IDEA中,点击 rabbit:connection-factory 标签,会跳转该标签所在jar包的xsd定义文件中;
==》修改成 spring-rabbit.xsd 后,应该是优先到jar包中找对应的xsd定义文件吧;
(TODO 有空要确认下spring在这方面的机制)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。