在使用Servlet API实现拦截器时,我获得了开箱即用的HandlerMethod:
... extends HandlerInterceptorAdapter
@Override
public boolean preHandle(final HttpServletRequest request,
final HttpServletResponse response, final Object handlerMethod) throws Exception {我可以在实现HandlerMethod而不是HandlerInterceptorAdapter的同时访问WebFilter吗?
在WebFilter的情况下,我有:
... implements WebFilter {
public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {曾经我可以通过调用serverWebExchange.getAttribute("....bestMatchingHandler")来访问HandlerMethod,但是它不再工作了。参见corresponding question。这里我的问题是:不使用serverWebExchange.getAttribute如何获得HandlerMethod
发布于 2018-08-14 20:45:17
我找到了答案,这个答案也有助于回答我最初的问题。可以通过以下方式获取HandlerMethod:
(HandlerMethod) this.handlerMapping.getHandler(serverWebExchange).toProcessor().peek();其中,handlerMapping是可以从WebFlux注入的RequestMappingHandlerMapping类型的bean。
https://stackoverflow.com/questions/51840647
复制相似问题