WebMvcConfig.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.base.RedisService;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.web.servlet.config.annotation.*;
  10. /**
  11. * @author TRX
  12. * @date 2024/3/21
  13. */
  14. @Slf4j
  15. @Configuration
  16. public class WebMvcConfig implements WebMvcConfigurer {
  17. @Autowired
  18. private AuthSettings authSettings;
  19. @Autowired
  20. private JWTManager jwtManager;
  21. @Autowired
  22. private RedisService redisService;
  23. @Override
  24. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  25. registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
  26. registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
  27. // registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
  28. // registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
  29. }
  30. /**
  31. * 请求拦截器
  32. */
  33. @Override
  34. public void addInterceptors(InterceptorRegistry registry) {
  35. registry.addInterceptor(new UserContextInterceptor(authSettings, jwtManager, redisService));
  36. }
  37. @Override
  38. public void addCorsMappings(CorsRegistry registry) {
  39. log.info("addCorsMappings...");
  40. registry.addMapping("/**").allowedOrigins("*").allowedMethods("*");
  41. // registry.addMapping("/**")
  42. // .allowedOriginPatterns("*")
  43. // .allowCredentials(false)
  44. // .allowedOrigins("*")
  45. // .allowedHeaders("*")
  46. // .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
  47. // .maxAge(3600);
  48. }
  49. }