Spring 集成网关错误通道 - 没有这样的 bean 异常

Spring Integration gateway error channel - no such bean exception

我已经配置了一个 spring 集成网关,其中包含一个由线程池支持的服务激活器。 一切正常,直到我尝试添加自己的错误通道。 Spring 开始抱怨无法通过错误通道的名称找到 bean。

这是我的 xml 配置:

    <int:gateway service-interface="Messaging.SendMessageToDeviceGateWay"
        error-channel="send_message_to_device_error_channel"
        default-request-channel="send_message_to_device_channel" 
        id="send_message_to_device_gateway">

        </int:gateway>

    <int:channel id="send_message_to_device_channel">
        <int:queue message-store="redisMessageStore" />
    </int:channel>

    <bean id="sendMessageToDeviceServiceBeanId" class="Messaging.SendMessageToDeviceService" />

    <int:service-activator input-channel="send_message_to_device_channel"
        ref="sendMessageToDeviceServiceBeanId" method="send_message">
        <int:poller fixed-rate="500" time-unit="MILLISECONDS"
            task-executor="send_message_to_device_task_executor" receive-timeout="0" />
    </int:service-activator>


    <bean id="sendMessageToDeviceErrorHandlerBeanId" 
        class="Messaging.SendMessageToDeviceErrorHandler" />



    <int:service-activator input-channel = "send_message_to_device_error_channel"
        ref="sendMessageToDeviceErrorHandlerBeanId" method="handle_error">
    </int:service-activator>

我看到的错误是:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'send_message_to_device_gateway': Cannot resolve reference to bean 'send_message_to_device_error_channel' while setting bean property 'errorChannel'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'send_message_to_device_error_channel' 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.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 24 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'send_message_to_device_error_channel' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 37 more

它为什么要寻找那个名字的 bean?

提前致谢, 理查德.

正确:任何 bean 都必须出现在应用程序上下文中。

即使您使用默认 errorChannel,它也会由 Spring 集成基础架构填充到应用程序上下文中。

因此,无论如何您都必须提供 <channel id="send_message_to_device_error_channel"/>