| | |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Configuration |
| | | public class WebConfig implements WebMvcConfigurer { // 实现WebMvcConfigurer |
| | | @Autowired |
| | | @Resource |
| | | private final OpenCryptUtil openCryptUtil; |
| | | private final TokenInterceptor tokenInterceptor; |
| | | |
| | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(tokenInterceptor) |
| | | .addPathPatterns("/**"); // 拦截/api/开头的请求(按需调整) |
| | | // .excludePathPatterns( // 排除不需要拦截的路径(如登录、注册接口) |
| | | // "/api/login", |
| | | // "/api/register", |
| | | // "/error" // 排除错误页 |
| | | // ); |
| | | .addPathPatterns("/**")// 拦截/api/开头的请求(按需调整) |
| | | .excludePathPatterns( // 排除不需要拦截的路径(如登录、注册接口) |
| | | "/index/**", |
| | | "/auth/**", |
| | | "/swagger-ui.html", |
| | | "/swagger-resources/**", |
| | | "/v2/api-docs", |
| | | "/webjars/**" |
| | | |
| | | ); |
| | | } |
| | | } |