gpt4 book ai didi

java - 在 Spring 集成中将字符串对象发送到休息服务时 ConverterNotFoundException

转载 作者:太空宇宙 更新时间:2023-11-04 12:43:20 26 4
gpt4 key购买 nike

我正在尝试通过 http:outbound-gateway 将 JSON 字符串从 spring-integration 发送到 REST 服务。

但出现错误

No converter found capable of converting from type java.lang.String to type org.springframework.http.ResponseEntity<?>

分享相关细节

<int-http:outbound-gateway id="xtifygateway"
request-channel="requestchannel" request-factory="requestFactory"
url="${xtifyUrl}" http-method="POST">
</int-http:outbound-gateway>

<int:header-enricher input-channel="requestchannel">
<int:header name="Content-Type" value="application/json"/>
</int:header-enricher>

发送请求的接口(interface)是

public interface RequestGateway
{
ResponseEntity<?> pushNotification(String xtifyRequest);
}

我在java中使用这段代码并调用接口(interface)方法。

  ObjectMapper objectMapper = new ObjectMapper(); 
try {
String xtifyJson = objectMapper.writeValueAsString(xtifyRequest);
}

有人可以帮忙解决这个问题吗?我在这里缺少什么?

最佳答案

我认为您正在寻找这个:

     <xsd:attribute name="expected-response-type" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
The expected type to which the response body should be converted.
Default is 'org.springframework.http.ResponseEntity'.
This attribute cannot be provided if expected-response-type-expression has a value
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="direct">
<tool:expected-type type="java.lang.Class" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>

从一方面来看,String 应该足够了,但从其​​他方面考虑,请考虑使用一些您的域对象。 MappingJackson2HttpMessageConverter 将为您解决这个问题。

关于java - 在 Spring 集成中将字符串对象发送到休息服务时 ConverterNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36597773/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com