Spring 无论如何调用引导拦截器排除模式

Spring Boot Interceptor called anyway of exclude pattterns

拦截器注册于:

@Override
protected void addInterceptors(final InterceptorRegistry registry) {
    registry.addInterceptor(new ThymeleafLayoutInterceptor()).addPathPatterns("/**").excludePathPatterns("/json/**").excludePathPatterns("/static/**");
}

据我了解,拦截器应为每个请求调用,但不会为带有
的请求调用 /静态/

/json/ 在他们的路径中。 但是,拦截器似乎是从每个资源调用的,也从路径中带有静态的资源调用的。

在我的拦截器的 PostHandle 方法中打印出来

final ResourceHttpRequestHandler h = (ResourceHttpRequestHandler) handler;
System.out.println(h.getLocations());

结果

[class path resource [static/]]

我试过这样的模式
1./静态/**
2. /静态/*,
3. /静态/
4.静态/

这怎么可能,我该如何解决这个问题?

您正在调用 excludePathPatterns 两次。

这应该可以完成工作

@Override
protected void addInterceptors(final InterceptorRegistry registry) {
    registry.addInterceptor(new ThymeleafLayoutInterceptor())
            .addPathPatterns("/**")
            .excludePathPatterns("/json/**", "/static/**");
}