package com.emotion.config; import com.emotion.interceptor.AdminAuthInterceptor; import com.emotion.interceptor.JwtAuthInterceptor; 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; /** * Web MVC配置 * * @author huazhongmin * @date 2025-07-23 */ @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Autowired private JwtAuthInterceptor jwtAuthInterceptor; @Autowired private AdminAuthInterceptor adminAuthInterceptor; @Override public void addInterceptors(InterceptorRegistry registry) { // 管理员拦截器 - 优先级最高,只拦截 /admin/** 路径 registry.addInterceptor(adminAuthInterceptor) .addPathPatterns("/admin/**") .excludePathPatterns( "/admin/auth/login", // 管理员登录接口 "/admin/auth/refreshToken" // 管理员刷新token接口 ) .order(1); // 优先级1,最先执行 // 普通用户拦截器 - 拦截除管理员路径外的所有请求 registry.addInterceptor(jwtAuthInterceptor) .addPathPatterns("/**") .excludePathPatterns( "/auth/login", // 登录接口 "/auth/register", // 注册接口 "/auth/captcha", // 图形验证码接口 "/auth/sms-code", // 短信验证码接口(免登录) "/auth/refresh-token", // 刷新token接口 "/auth/resetPassword", // 重置密码接口(免登录) "/analytics/events/batch", // Analytics event batch endpoint "/health", // 健康检查接口 "/ws/**", // WebSocket接口 "/swagger-ui/**", // Swagger UI "/v3/api-docs/**", // API文档 "/actuator/**", // 监控端点 "/admin/**" // 排除管理员路径,由管理员拦截器处理 ) .order(2); // 优先级2 } }