我正在尝试向 REST 端点发送一个简单的 POST 请求。我有一个简单的 pojo,我想将其作为 JSON 发送到有效负载中。这是 pojo(请注意,我将 Spring Integration 与 grails 结合使用,因此 pojo/服务在 Groovy 中):
class Person implements Serializable {
String name
}
这是我的网关:
public interface PersonGateway {
Person savePerson(Person person)
}
这里是布线的重要部分:
<int:channel id="requestChannel" />
<int:channel id="responseChannel" />
<int:header-enricher input-channel="requestChannel">
<int:header name="Content-Type" value="application/json" />
</int:header-enricher>
<int:gateway id="PersonGateway"
service-interface="com.example.PersonGateway"
default-request-channel="requestChannel"
default-reply-channel="responseChannel">
<int:method name="savePerson" />
</int:gateway>
<int-http:outbound-gateway url="http://127.0.0.1:8000/person"
http-method="POST"
message-converters="jsonConverter"
expected-response-type="com.example.Person"
request-channel="requestChannel"
extract-request-payload="false"/>
此 POST 请求永远不会到达该服务,但不会抛出任何异常。当我记录所有级别时,我得到的唯一看起来像线索的是:
2014-03-30 16:35:07,313 [main] DEBUG outbound.HttpRequestExecutingMessageHandler - Unable to attempt conversion of Message payload types. Component 'org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler#0' has no explicit ConversionService reference, and there is no 'integrationConversionService' bean within the context.
除此之外,它并没有给我太多。我整天都在尝试一些小事情,但似乎无济于事。有人看到我错过了什么吗?谢谢!
最佳答案
Unable to attempt conversion of Message payload types.
别担心:它对你没有值(value)。在大多数情况下,我们可以在没有它的情况下生活在我们的应用程序中integrationConversionService
.这里需要表达式。由于您不使用任何表达式,因此该 WARN 不会伤害您。你说你要将 POJO 作为 JSON 发送,那么你不应该使用
extract-request-payload="false"
.与false
<int-http:outbound-gateway>
放置到整个请求主体Message<?>
和变化content-type
至application/x-java-serialized-object
希望你的
jsonConverter
围绕 POJO <-> JSON 做正确的事情
关于java - Http 出站网关从 pojo 负载发送 Json 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22750403/