我有一个应该为查询参数提供服务并返回响应的配置。这是我的配置。不幸的是,Spring无法创建。
<int-http:inbound-gateway request-channel="inChannel"
reply-channel="outChannel" supported-methods="GET"
path="/ticket">
<int-http:request-mapping consumes="text/plain" params="param1,param2,param3"
produces="text/plain" />
</int-http:inbound-gateway>
<int:service-activator ref="ticketIssuingService" method="processTicket"
input-channel="inChannel" output-channel="outChannel"/>@MessageEndpoint
public class TicketIssuingService {
public String processTicket(??? payload){
System.out.println("Query Paramter String is "+payload);
return null;
}
}m3=duration
如何检索参数以便切换到processTicket方法?Spring抱怨说没有找到合适的方法。processTicket方法的参数应该是什么?请帮帮忙
发布于 2016-05-03 19:20:07
对于没有GET的payload-expression方法,用于inChannel的Message<?>的payload恰好是以下对象:
MultiValueMap<String, String> requestParams = this.convertParameterMap(servletRequest.getParameterMap());
...
if (payload == null) {
if (requestBody != null) {
payload = requestBody;
}
else {
payload = requestParams;
}
}因此,这应该是关于payload服务方法中的processTicket类型的问题的答案。
请注意,您可以通过payload-expression定制该payload-expression,并使用一些内置的SpEL EvaluationContext 变量,例如:
#requestParams - the MultiValueMap from the ServletRequest parameterMap.
#pathVariables - the Map from URI Template placeholders and their values;
#matrixVariables - the Map of MultiValueMap according to Spring MVC Specification. Note, #matrixVariables require Spring MVC 3.2 or higher;
#requestAttributes - the org.springframework.web.context.request.RequestAttributes associated with the current Request;
#requestHeaders - the org.springframework.http.HttpHeaders object from the current Request;
#cookies - the Map<String, Cookie> of javax.servlet.http.Cookie s from the current Request. 有些示例是这样获得queryString的
payload-expression="T(org.springframework.web.context.request.RequestContextHolder).requestAttributes.request.queryString"https://stackoverflow.com/questions/37012427
复制相似问题