| | |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.Ordered; |
| | | import org.springframework.web.cors.CorsConfiguration; |
| | | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
| | | import org.springframework.web.filter.CorsFilter; |
| | | import org.springframework.web.servlet.config.annotation.CorsRegistry; |
| | | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| | | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
| | | |
| | | /** |
| | | * @author wMeng |
| | | * @ClassName CorsConfig |
| | | * @Description 跨域配置 |
| | | * @date 2022/10/31 16:42 |
| | | * @Version 1.0 |
| | | */ |
| | | @Configuration |
| | | public class CorsConfig extends WebMvcConfigurationSupport { |
| | | @Override |
| | | public void addViewControllers(ViewControllerRegistry registry) { |
| | | registry.addViewController("/").setViewName("redirect:/doc.html"); |
| | | registry.setOrder(Ordered.HIGHEST_PRECEDENCE); |
| | | } |
| | | |
| | | @Override |
| | | public void addCorsMappings(CorsRegistry registry) { |
| | | registry.addMapping("/**") |
| | | .allowCredentials(true) |
| | | .allowedOrigins("*") |
| | | .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") |
| | | .maxAge(3600) |
| | | .allowCredentials(true); |
| | | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
| | | .allowedHeaders("*") |
| | | .maxAge(3600); |
| | | } |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | //设置静态资源映射 |
| | | registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/"); |
| | | registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/"); |
| | | |