【发布时间】:2018-10-13 11:21:49
【问题描述】:
在我的带有 Spring Integration http 出站网关的 Spring Boot 应用程序中,我收到了 http 错误代码 415。所以我在配置中添加了一个 headerMapper bean,但这会抛出 NotWritablePropertyException。消息是 属性“Content-Type”不可写或具有无效的 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" />
请求网关
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 年 5 月 17 日更新
按照 Artem Bilan 的建议配置 header-enricher 后,我现在收到以下错误:
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)
【问题讨论】:
标签: spring-boot spring-integration