package com.seecoder.BlueWhale.configure; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @Author: DingXiaoyu * @Date: 0:17 2023/11/26 * * 这个类实现了WebMvcConfigurer接口, * 表示会被SpringBoot接受, * 这个类的作用是配置拦截器。 * addInterceptors方法配置了拦截器, * 添加了loginInterceptor作为拦截器, * 并且设置除了register和login的所有接口都需要通过该拦截器。 */ @Configuration public class MyWebMvcConfig implements WebMvcConfigurer { @Autowired LoginInterceptor loginInterceptor; @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(loginInterceptor) .addPathPatterns("/**") .excludePathPatterns("/api/users/register") .excludePathPatterns("/api/users/login") .excludePathPatterns("/api/ali/*") .order(1); } }