package com.zswl.dataservice.config; import com.zswl.dataservice.auth.AuthSettings; import com.zswl.dataservice.auth.JWTManager; import com.zswl.dataservice.auth.UserContextInterceptor; import com.zswl.dataservice.service.RedisService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.reflect.FieldUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.util.ReflectionUtils; import org.springframework.web.servlet.config.annotation.*; import java.lang.reflect.Field; import java.util.List; /** * @author TRX * @date 2024/3/21 */ @Slf4j @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Autowired private AuthSettings authSettings; @Autowired private JWTManager jwtManager; @Autowired private RedisService redisService; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); // registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); // registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } /** * 请求拦截器 */ @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new UserContextInterceptor(authSettings, jwtManager, redisService)); } @Override public void addCorsMappings(CorsRegistry registry) { log.info("addCorsMappings..."); registry.addMapping("/**").allowedOrigins("*").allowedMethods("*"); // registry.addMapping("/**") // .allowedOriginPatterns("*") // .allowCredentials(false) // .allowedOrigins("*") // .allowedHeaders("*") // .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // .maxAge(3600); } }