首页 > 解决方案 > Spring 集成:带有 Jaxb2RootElementHttpMessageConverter 的 Http 出站网关

问题描述

我必须为不同的端点调用外部服务。有http-outbound网关。每个端点接受不同的数据,例如jsonxml。以下是生产/消费的配置xml

<int-http:outbound-gateway
        id="ca.outbound.gateway" 
        request-channel="ca.request.channel" url-expression="http://localhost:9988/current/acct/create"
        http-method-expression="POST"
        message-converters="Jaxb2RootElementHttpMessageConverter"
        expected-response-type-expression="com.ds.Account"      
        charset="UTF-8" reply-timeout="5000" reply-channel="ca.reply.channel">
</int-http:outbound-gateway>

但是在启动应用程序时,出现如下错误: APPLICATION FAILED TO START

A component required a bean named 'Jaxb2RootElementHttpMessageConverter' that could not be found.

Consider defining a bean named 'Jaxb2RootElementHttpMessageConverter' in your configuration.

注意Jaxb2RootElementHttpMessageConverter类存在于 Classpath 中Spring-web-5.0.5.RELEASE.jar

我不确定如何解决此错误。

标签: springspring-integration

解决方案


该错误清楚地表明您对此一无所知。您在类路径中有一个类这一事实并不意味着您自动为它获得了一个 bean。你真的应该这样声明:

<bean id="jaxb2RootElementHttpMessageConverter" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>

然后将其用作该属性id的引用。message-converters

请考虑了解有关 Spring 的更多信息:https ://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#spring-core


推荐阅读