spring - Spring 集成:带有 Jaxb2RootElementHttpMessageConverter 的 Http 出站网关
问题描述
我必须为不同的端点调用外部服务。有http-outbound
网关。每个端点接受不同的数据,例如json
或xml
。以下是生产/消费的配置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
。
我不确定如何解决此错误。
解决方案
该错误清楚地表明您对此一无所知。您在类路径中有一个类这一事实并不意味着您自动为它获得了一个 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
推荐阅读
- java - 无法将 Spring 连接到 PostgreSQL
- c# - 如何获取内置类型别名的字符串表示
- c# - 如何使用 RelayCommand 类
- export-to-csv - Akeneo 导出中缺少记录
- prolog - 为什么我的谓词 div/4 在给我一个答案后进入无限循环?
- python - 如何在 python 3 代码中将表名作为变量传递给 PostgreSQL 查询并防止 SQL 注入?
- php - CodeIgniter Rest_Controller:API 密钥无效
- android - 创建自定义 toast 时 findViewById() 不能为空
- python-3.x - 使用不均匀的镜头创建字典
- javascript - \b 正则表达式用于词尾