| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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.base.RedisService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.*;
- /**
- * @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);
- }
- }
|