将 Spring Integration 5.1.3.RELEASE 更新到 5.5.18 时,“标头值路由器”的“默认输出通道”出现“组件需要 bean”错误

问题描述 投票:0回答:1

我正在将 Spring Boot 从 2.1 更新到 2.5(最终更新到 3.2),但遇到了 Spring Integration 的问题,我无法在 Spring Integration 迁移指南 中找到解决方案文档服务激活器文档

基本上,在我将 Spring Integration 从 5.1.3.RELEASE 更新到 5.5.18(通过 Spring Boot 依赖项 v2.5.15)后,我收到以下启动错误:“一个组件需要一个名为‘unsupportedOutGatewayChannel’的 bean,它可以找不到。”我在“链”中的“标头值路由器”中使用“unsupportedOutGatewayChannel”作为“默认输出通道”:

  <integration:chain input-channel="outboundRouterChannel">
      <integration:header-enricher>
        <!-- Set header to 'application/json' so that our POJO is converted to JSON by the
             MappingJackson2HttpMessageConverter converter before sending outside. -->
        <integration:header name="#{T(org.springframework.http.HttpHeaders).CONTENT_TYPE}"
                            value="#{T(org.springframework.http.MediaType).APPLICATION_JSON_VALUE}" />
      </integration:header-enricher>
 
      <!-- Based on the header value for destination type, routing message to an appropriate out channel -->
      <integration:header-value-router header-name="#{T(com.router.common.ApplicationConstants).HEADER_DESTINATION_TYPE}"
                                       resolution-required="false"
                                       default-output-channel="unsupportedOutGatewayChannel">
        <integration:mapping value="#{T(com.router.common.model.Constants.ROUTING_DESTINATION_TYPE).REST}"
                             channel="outGatewayForRestChannel" />
        <integration:mapping value="#{T(com.router.common.model.Constants.ROUTING_DESTINATION_TYPE).FTP}"
                             channel="outGatewayForFtpChannel" />
      </integration:header-value-router>
  </integration:chain>

它是通过@MessageEndpoint注释类的@ServiceActivator注释方法在代码中定义的:

    @MessageEndpoint
    public class OutsideRouter
    {
     ...
     
        @ServiceActivator(inputChannel="unsupportedOutGatewayChannel")
        public void handleUnsupportedDestinationType(ExternalRoutableMessage incomingMessage, @Headers Map<String, Object> headerMap)
        {
            String messageId = headerMap.get(HEADER_MESSAGE_ID).toString();
            String destinationType = headerMap.get(HEADER_DESTINATION_TYPE).toString();
            throw new UnsupportedDestinationTypeException(format("Unable to route message with id '%s': destination is of "
                    + "unsupported type '%s'", messageId, destinationType));
        }
     ...

我知道它希望我用这样的名称定义一个 bean,显然我知道该怎么做。但我想知道它在 5.1.3.RELEASE 版本(Spring Boot 2.1.3.RELEASE)中工作正常而在 5.5 中不起作用的原因。

您能指出我正确的方向吗?谢谢!

spring-integration
1个回答
0
投票

类似

@ServiceActivator
的注释稍后会在
ApplicationContext
生命周期中进行解析,然后解析bean引用以获取类似
<integration:header-value-router>
的bean定义。

我们可能没有预料到会有这样的配置组合,其中尝试在 XML 中使用任何可以通过注释自动创建的内容。

所以,或者您尝试完全迁移到 Java 或 XML 配置,或者只是声明简单的

<integation:channel id="unsupportedOutGatewayChannel"/>

© www.soinside.com 2019 - 2024. All rights reserved.