MVC Java配置-HandlerInterceptor不排除路径


问题内容

我有一个MVC Java配置,但是HandlerInterceptor不排除某些模式。

在标有 xxx 的行上,如果

1)我同时添加addPatterns("/**")excludePathPatterns("*.ecxld")HandlerInterceptorInterceptorRegistration时,HandlerInterceptor.preHanlde()是不是在所有调用。例如.addPathPatterns("/**").excludePathPatterns("*.ecxld")

2)我只添加excludePathPatterns("*.ecxld")HandlerInterceptorInterceptorRegistration,则HandlerInterceptor.preHanlde()仍执行。

(其他拦截器调用正常)。

任何指针表示赞赏。

谢谢

@Configuration
public class MyMVCConfigurerAdapter extends WebMvcConfigurerAdapter {

 @Override
 public void addInterceptors(final InterceptorRegistry registry) {

     registry.addInterceptor(getInterceptorOne());

     registry.addInterceptor(getMyHandlerInterceptor())
                 .excludePathPatterns("*.ecxld");  // **xxx**

     registry.addInterceptor(getInterceptorTwo()
     );

 }

问题答案:

调试后,拦截器不会按照添加顺序执行。在上面的示例中,先执行interceptorOne,然后是interceptorTwo,然后执行处理程序(具有排除的模式)。