HttpRequestHandlingMessagingGateway PayloadExpression java 配置
HttpRequestHandlingMessagingGateway PayloadExpression java config
我想使用 HttpRequestHandlingMessagingGateway::setPayloadExpression
将请求值映射到我的模型对象。我找到 this answer,但没能用 java 配置做同样的事情。如果有人能提供一个例子,那就太好了。
我的代码:
@Bean
public HttpRequestHandlingMessagingGateway httpViewGate() {
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
RequestMapping requestMapping = new RequestMapping();
requestMapping.setMethods(HttpMethod.GET);
requestMapping.setPathPatterns("/foo");
requestMapping.setProduces(MediaType.APPLICATION_JSON_VALUE);
gateway.setRequestMapping(requestMapping);
gateway.setRequestChannel(intConfig.viewFlowRequestChannel());
gateway.setPayloadExpression(???); //what to do here
gateway.setRequestPayloadType(ViewClientCriteria.class);// this may not be required
return gateway;
}
另外,如果有另一种更灵活的方法来做同样的事情,我也很感兴趣。
我使用Spring Boot 1.2.4
Expression payloadExpression = new SpelExpressionParser().parseExpression("...");
gateway.setPayloadExpression(payloadExpression);
我想使用 HttpRequestHandlingMessagingGateway::setPayloadExpression
将请求值映射到我的模型对象。我找到 this answer,但没能用 java 配置做同样的事情。如果有人能提供一个例子,那就太好了。
我的代码:
@Bean
public HttpRequestHandlingMessagingGateway httpViewGate() {
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
RequestMapping requestMapping = new RequestMapping();
requestMapping.setMethods(HttpMethod.GET);
requestMapping.setPathPatterns("/foo");
requestMapping.setProduces(MediaType.APPLICATION_JSON_VALUE);
gateway.setRequestMapping(requestMapping);
gateway.setRequestChannel(intConfig.viewFlowRequestChannel());
gateway.setPayloadExpression(???); //what to do here
gateway.setRequestPayloadType(ViewClientCriteria.class);// this may not be required
return gateway;
}
另外,如果有另一种更灵活的方法来做同样的事情,我也很感兴趣。
我使用Spring Boot 1.2.4
Expression payloadExpression = new SpelExpressionParser().parseExpression("...");
gateway.setPayloadExpression(payloadExpression);