SpringBoot2.0拦截器WebMvcConfigurationSupport
错误如图所示
控制台信息
页面测试
解决方案
addResourceHandlers
- 重写
WebMvcConfigurationSupport
中的addResourceHandlers
方法,添加对静态资源目录的过滤
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| package com.zby.config;
import com.zby.interceptor.JwtInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Component @Configuration public class JwtConfiguration extends WebMvcConfigurationSupport {
@Autowired private JwtInterceptor jwtInterceptor;
@Override protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor).addPathPatterns("/**") .excludePathPatterns("/user/login/**","/arsenal/view","/user/index/**"); }
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") .addResourceLocations("classpath:/static/"); registry.addResourceHandler("/templates/**") .addResourceLocations("classpath:/templates/"); super.addResourceHandlers(registry); }
}
|
- 验证