我有一个SpringBoot 2.2.6
应用程序,我想用spring-integration
设置一个端点,因此我有以下配置:
@Bean
public MessageChannel reply() {
return new DirectChannel();
}
@Bean
public IntegrationFlow inbound(TestTransformer testTransformer) {
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.GET))
.replyChannel("reply")
.requestPayloadType(String.class))
.channel("httpRequest")
.get();
}
@Bean
@ServiceActivator(inputChannel = "httpRequest", outputChannel = "reply")
public Function<Message<?>, String> handler() {
return new Function<Message<?>, String>() {
public String apply(Message<?> message) throws MessagingException {
log.info("myHandler: " + message.getPayload());
log.info("myHandler: " + message.getHeaders());
return "ok";
}
};
}
现在,如果我调用端点作为http://localhost:8080/MyApp/foo?q=test&q1=test2
传递参数,我将收到JSON
形式的参数。
可以在MVC中接收@PathVariable
之类的东西,例如:
return IntegrationFlows.from(Http.inboundGateway("/foo/{name}")
我已经尝试过,但不工作,我找不到任何文档谈论(至少与java bean配置)
感谢Maybe:
@Bean
public IntegrationFlow test(TestTransformer testTransformer, Jackson2JsonObjectMapper obj) {
return IntegrationFlows.from(Http.inboundGateway("/foo/{name}")
.requestMapping(m -> m.methods(HttpMethod.GET))
.payloadExpression("#pathVariables.name")
.replyChannel("reply")
.requestPayloadType(String.class))
.transform(testTransformer)
.transform(new ObjectToJsonTransformer(obj))
.channel("httpRequest")
.get();
}
更有用…文档中有很多xml配置文件,我读了但是我不能把它们都转换成java DSL