package com.xiaopeng.map.config; import com.xiaopeng.map.config.interceptor.SafeCheckForClientInterceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import javax.annotation.Resource; @Slf4j @Configuration public class MiniprogramConfigurer extends WebMvcConfigurerAdapter { @Resource @Lazy private SafeCheckForClientInterceptor safeCheckForClientInterceptor; @Override public void addInterceptors(InterceptorRegistry registry) { try { log.info("正在注册小程序拦截器..."); // 使用安全的统一验证服务拦截器,避免 ClassCastException registry.addInterceptor(safeCheckForClientInterceptor) .addPathPatterns("/base/v1/mini-program/**", "/api/v1/mini-program/**") .excludePathPatterns("/base/v1/mini-program/fence/check" , "/base/v1/mini-program/cities/list" , "/base/v1/mini-program/point/getPointByIp"); log.info("小程序拦截器注册成功"); } catch (Exception e) { log.warn("小程序拦截器注册失败: {}", e.getMessage()); } } }