Yury K.
Yury K.

Reputation: 671

"A component required a bean" error for "default-output-channel" of a "header-value-router" when updating Spring Integration 5.1.3.RELEASE to 5.5.18

I'm in a process of updating Spring Boot from 2.1 to 2.5 (and eventually to 3.2), but facing an issue with Spring Integration which I'm not able to find a solution for in either Spring Integration Migration Guides, documentation or Service Activator documentation.

Basically, after I have updated Spring Integration from 5.1.3.RELEASE to 5.5.18 (via Spring Boot Dependencies v2.5.15), I've got the following startup error: "A component required a bean named 'unsupportedOutGatewayChannel' that could not be found." I am using 'unsupportedOutGatewayChannel' as "default-output-channel" in "header-value-router" in a "chain":

  <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>

and it's defined in the code via @ServiceActivator annotated method of a @MessageEndpoint annotated class:

    @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));
        }
     ...

I understand that it wants me to define a bean with such name and obviously I know how to do that. But I would like to know the reason behind it working fine in version 5.1.3.RELEASE (Spring Boot 2.1.3.RELEASE) and not working in 5.5.

Could you please point me in the right direction here? Thank you!

Upvotes: 0

Views: 36

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121542

Annotations like that @ServiceActivator are parsed a bit later in the ApplicationContext lifecylce, then bean references are resolved for bean definitions like that <integration:header-value-router>.

We probably didn't anticipate such a mix of configurations, where there is an attempt to use in XML whatever could be auto-created by annotations.

So, or you try to migrate fully to Java or XML config, or just declare that simple <integation:channel id="unsupportedOutGatewayChannel"/>!

Upvotes: 2

Related Questions