在我使用Spring Integration http出站网关的Spring Boot应用程序中,我得到了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" />
请求网关
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)
答案 0 :(得分:1)
我想你的意思是header-enricher
之前的http:Outbound-Gateway
。您需要填充此类标头,同时映射器即将为请求添加现有标头。