Spring boot Spring集成:NotWritablePropertyException-无效的属性“内容类型”

Spring boot Spring集成:NotWritablePropertyException-无效的属性“内容类型”,spring-boot,spring-integration,Spring Boot,Spring Integration,在使用Spring集成http出站网关的Spring引导应用程序中,我得到了http错误代码415。因此,我向配置中添加了一个headerMapper bean,但这会引发NotWritablePropertyException。消息为属性“内容类型”不可写或具有无效的setter方法。参数类型是否正确 setter的返回类型是否与getter的返回类型匹配 配置: <int:gateway id="requestGateway" service-interface="org.my

在使用Spring集成http出站网关的Spring引导应用程序中,我得到了http错误代码415。因此,我向配置中添加了一个headerMapper bean,但这会引发NotWritablePropertyException。消息为属性“内容类型”不可写或具有无效的setter方法。参数类型是否正确 setter的返回类型是否与getter的返回类型匹配

配置:

<int:gateway id="requestGateway"
    service-interface="org.myorg.springintegration.gateway.http.RequestGateway"
    default-request-channel="post_send_channel" />

<int:channel id="post_send_channel" />

<int:header-enricher input-channel="post_send_channel">
    <int:header name="Content-Type" value="application/json; charset=utf8"/>
</int:header-enricher>

<int-http:outbound-gateway
    request-channel="post_send_channel"
    url="http://localhost:8080/incomes" http-method="POST"
    expected-response-type="java.lang.String" />
我猜你指的是http:出站网关之前的头enricher。您需要填充这样的头,同时映射程序将要向请求添加现有头,或者不添加现有头


有关更多信息,请参阅参考手册:

谢谢您的指导。我在配置中添加了一个标题充实器。现在我得到org.springframework.core.convert.ConverterNotFoundException:没有找到能够从[java.util.HashMap]类型转换为[java.lang.String]类型的转换器。你能给我一个指针来修正这个错误吗?你需要用更多的堆栈跟踪来编辑你的问题,以确定错误发生的位置
public interface RequestGateway {
    String echo(Map<String, String> request);
}
@SpringBootApplication
public class HttpApplication {

    public static void main(String[] args) {
        SpringApplication.run(HttpApplication.class, args);

        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("http-outbound-gateway.xml");

        Map<String, String> postMap = new HashMap<String, String>();
        postMap.put("amount", "2000");
        postMap.put("description", "Second Income");

        RequestGateway rg = context.getBean("requestGateway", RequestGateway.class);
        System.out.println(rg.echo(postMap));

        context.close();
    }
}
2018-05-17 12:30:48.354  INFO 4452 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started _org.springframework.integration.errorLogger
[WARNING]
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.HashMap<?, ?>] to type [java.lang.String]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound (GenericConversionService.java:321)
    at org.springframework.core.convert.support.GenericConversionService.convert (GenericConversionService.java:194)
    at org.springframework.core.convert.support.GenericConversionService.convert (GenericConversionService.java:174)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.convert (GatewayProxyFactoryBean.java:755)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod (GatewayProxyFactoryBean.java:527)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke (GatewayProxyFactoryBean.java:469)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke (GatewayProxyFactoryBean.java:460)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy79.echo (Unknown Source)
    at org.javacodegeeks.springintegration.gateway.http.HttpApplication.main (HttpApplication.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)