1、对于WebMvcConfigurer配置了拦截过滤不生效的问题(我的项目在yml中配置了server:contest-path)
server:
port: 8081
max-http-header-size: 100MB
servlet:
context-path: /api
2、原来在WebMvcConfigurer实现类中的addInterceptors()方法中所写的内容
@Override
public void addInterceptors(InterceptorRegistry registry) {
InterceptorRegistration addInterceptor=registry.addInterceptor(apiInterceptor);
List<String> excludeURLS = new ArrayList<>();
excludeURLS.add("/api/SendPhoneMessage");
excludeURLS.add("/api/getValidationCode");
excludeURLS.add("/api/ProcessRateWebSocket");
excludeURLS.add("/api/downloadBatchAddTemplate");
excludeURLS.add("/api/download");
addInterceptor.addPathPatterns("/**").excludePathPatterns(excludeURLS);
}
3、问题:当配置了/api/download拦截过滤后请求/api/download不生效
4、原因:在doDispatch中获取要匹配的循环请求路径时是不会添加前缀/api的,是直接在HandlerMapping中获取的路径
5、解决:将请求过滤中的/api去掉,然后请求/api/download可以正常访问
@Override
public void addInterceptors(InterceptorRegistry registry) {
InterceptorRegistration addInterceptor=registry.addInterceptor(apiInterceptor);
List<String> excludeURLS = new ArrayList<>();
excludeURLS.add("/SendPhoneMessage");
excludeURLS.add("/getValidationCode");
excludeURLS.add("/ProcessRateWebSocket");
excludeURLS.add("/downloadBatchAddTemplate");
excludeURLS.add("/download");
addInterceptor.addPathPatterns("/**").excludePathPatterns(excludeURLS);
}