|
@@ -2,7 +2,11 @@ package com.gyee.wisdom.alarm.sharding.config;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+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.*;
|
|
|
|
|
|
/**
|
|
@@ -40,6 +44,23 @@ public class MyWebAppConfigurer implements WebMvcConfigurer {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Bean
|
|
|
+ public CorsFilter corsFilter() {
|
|
|
+ CorsConfiguration config = new CorsConfiguration();
|
|
|
+ //允许白名单域名进行跨域调用
|
|
|
+ config.addAllowedOriginPattern("*");
|
|
|
+ //允许跨越发送cookie
|
|
|
+ config.setAllowCredentials(true);
|
|
|
+ //放行全部原始头信息
|
|
|
+ config.addAllowedHeader("*");
|
|
|
+ //允许所有请求方法跨域调用
|
|
|
+ config.addAllowedMethod("*");
|
|
|
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
+ source.registerCorsConfiguration("/**", config);
|
|
|
+ return new CorsFilter(source);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
registry.addResourceHandler("swagger-ui/")
|