在Spring Integration

时间:2016-04-13 12:03:26

标签: java spring spring-integration

我正在尝试通过http:outbound-gateway从Spring集成向REST服务发送JSON字符串。

但是得到了错误

  

找不到能够从类型java.lang.String转换为类型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>

用于发送请求的接口是

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

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

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

有人可以帮忙吗?我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找这个:

     <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将为您解决此问题。