2016-12-01 64 views

回答

1

我已经开始了解DispatcherServlet本身是如何决定使用这种方式来实现控制和实现的处理程序方法的。 这里是代码:

//Initialization in filter constructor 
.... 
final HandlerMapping handlerMappings = BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, HandlerMapping.class, true, false).get("requestMappingHandlerMapping"); 
.... 

@Override 
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { 
     ..... 
     Method mappingMethod = null; 
     try { 
      mappingMethod = ((HandlerMethod)handlerMappings.getHandler(request).getHandler()).getMethod(); 
      RequestMapping requestMapping = mappingMethod.getAnnotation(RequestMapping.class); 
      final String requestPattern = requestMapping.value(); 
     } 
     catch(Exception ex){ 
      logger.error("Error getting the mapping bean for the request URL " + request.getRequestURI(), ex); 
      return; 
     } 
     .... 
    } 
相关问题