WebMvcConfig.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.zswl.dataservice.config;
  2. import com.zswl.dataservice.auth.AuthSettings;
  3. import com.zswl.dataservice.auth.JWTManager;
  4. import com.zswl.dataservice.auth.UserContextInterceptor;
  5. import com.zswl.dataservice.service.RedisService;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.apache.commons.lang3.reflect.FieldUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.context.annotation.Configuration;
  10. import org.springframework.util.ReflectionUtils;
  11. import org.springframework.web.servlet.config.annotation.*;
  12. import java.lang.reflect.Field;
  13. import java.util.List;
  14. /**
  15. * @author TRX
  16. * @date 2024/3/21
  17. */
  18. @Slf4j
  19. @Configuration
  20. public class WebMvcConfig implements WebMvcConfigurer {
  21. @Autowired
  22. private AuthSettings authSettings;
  23. @Autowired
  24. private JWTManager jwtManager;
  25. @Autowired
  26. private RedisService redisService;
  27. @Override
  28. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  29. registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
  30. registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
  31. // registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
  32. // registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
  33. }
  34. /**
  35. * 请求拦截器
  36. */
  37. @Override
  38. public void addInterceptors(InterceptorRegistry registry) {
  39. registry.addInterceptor(new UserContextInterceptor(authSettings, jwtManager, redisService));
  40. }
  41. @Override
  42. public void addCorsMappings(CorsRegistry registry) {
  43. log.info("addCorsMappings...");
  44. registry.addMapping("/**").allowedOrigins("*").allowedMethods("*");
  45. // registry.addMapping("/**")
  46. // .allowedOriginPatterns("*")
  47. // .allowCredentials(false)
  48. // .allowedOrigins("*")
  49. // .allowedHeaders("*")
  50. // .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
  51. // .maxAge(3600);
  52. }
  53. }