关于 java:ConverterNotFoundException 在 spring 集成中将字符串对象发送到 rest 服务 | 珊瑚贝

ConverterNotFoundException on sending a string object to rest service in spring integration


我正在尝试通过 http:outbound-gateway.

从 spring-integration 向 REST 服务发送 JSON 字符串

但得到错误

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

分享相关细节

1
2
3
4
5
6
7
8
<inthttp:outboundgateway id=“xtifygateway”
        requestchannel=“requestchannel” requestfactory=“requestFactory”
        url=“${xtifyUrl}” httpmethod=“POST”>
</inthttp:outboundgateway>

<int:headerenricher inputchannel=“requestchannel”>
    <int:header name=“Content-Type” value=“application/json”/>
</int:headerenricher>

发送请求的接口是

1
2
3
4
public interface RequestGateway
{
    ResponseEntity< ? > pushNotification(String xtifyRequest);
}

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

1
2
3
4
  ObjectMapper objectMapper = new ObjectMapper();
  try {
      String xtifyJson = objectMapper.writeValueAsString(xtifyRequest);
  }

有人可以帮忙吗?我在这里错过了什么?


我想你正在寻找这个:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
     <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 expectedresponsetypeexpression has a value
            </xsd:documentation>
            <xsd:appinfo>
                <tool:annotation kind=“direct”>
                    <tool:expectedtype type=“java.lang.Class” />
                </tool:annotation>
            </xsd:appinfo>
        </xsd:annotation>
    </xsd:attribute>

一方面 String 应该足够了,但另一方面考虑使用一些你的域对象。 MappingJackson2HttpMessageConverter 将在这件事上为您工作。

  • ObjectMapper objectMapper = new ObjectMapper();尝试 { String xtifyJson = objectMapper.writeValueAsString(xtifyRequest);我在 java 中使用这段代码并调用接口方法。所以我应该删除它并使用 MappingJackson2HttpMessageConverter 吗?
  • 不,没关系。您只需将 expected-response-type 指定为 java.lang.String。


来源:https://www.codenong.com/36597773/

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?