rabbitmq 将Sping AMQP从1.3.4.RELEASE升级到1.5.5.RELEASE

zd287kbt  于 2023-02-22  发布在  RabbitMQ
关注(0)|答案(1)|浏览(266)

当我尝试将spring ampq从1.3.4.RELEASE升级到1.5.5.RELEASE时,我遇到了下面的错误。它工作正常,但当我尝试升级它时,抛出了一个错误。任何建议都将是有帮助的。这里是我的依赖项详细信息。

<dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>1.5.5.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>com.rabbitmq</groupId>
                    <artifactId>amqp-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.rabbitmq</groupId>
            <artifactId>amqp-client</artifactId>
            <version>4.8.0</version>
        </dependency>

我使用的 Spring 版本是4.2.3.RELEASE
错误详细信息:-

21-Feb-2023 16:12:58.148 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'que' defined in class path resource [config/spring/config-amqp.xml]: Cannot resolve reference to bean 'test' while setting bean property 'listeners' with key [0]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'test' is defined
                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)

下面是我配置xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:rabbit="http://www.springframework.org/schema/rabbit" xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.3.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">

    <beans profile="info">
        <!-- Consumers -->
        <rabbit:listener-container id="test"
            transaction-size="2" prefetch="2" error-handler="handler"
            connection-factory="connectionFactory" acknowledge="auto"
            concurrency="${t1.consmers}" advice-chain="valueTester">
            <rabbit:listener queues="${t2.consumer}, ${t3.tester}"
                ref="testConsumer" method="consume" />
        </rabbit:listener-container>

        
        <!-- Consumers manager -->
        <bean id="someid" class="java.util.concurrent.ConcurrentLinkedQueue" />
        <bean id="queue" class="com.t1.QueueTester">
            <property name="listeners">
                <list>
                    <ref bean="test" />
                </list>
            </property>
        </bean>
    </beans>

    <beans profile="build"></beans>

</beans>
new9mtju

new9mtju1#

查看几天前该版本的新增功能:https://docs.spring.io/spring-amqp/docs/current/reference/html/#listener-container-bean-names-xml
当迁移到这个版本时,如果您的<listener-container/>元素上有id属性,请删除它们并在子<listener/>元素上设置id。
这背后的原因是,过去您必须同时指定两个ID才能访问相应的侦听器。
最好还是升级到最新版本:所有这些都失去了支持多年。

相关问题