|
@@ -1,6 +1,10 @@
|
1
|
1
|
package com.cn.esermis.config;
|
2
|
2
|
|
|
3
|
+import org.springframework.context.annotation.Bean;
|
3
|
4
|
import org.springframework.context.annotation.Configuration;
|
|
5
|
+import org.springframework.web.cors.CorsConfiguration;
|
|
6
|
+import org.springframework.web.cors.CorsConfigurationSource;
|
|
7
|
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
4
|
8
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
5
|
9
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
6
|
10
|
|
|
@@ -15,4 +19,15 @@ public class CorsConfig implements WebMvcConfigurer {
|
15
|
19
|
.allowedHeaders("*") // 允许的请求头
|
16
|
20
|
.allowCredentials(true); // 是否允许证书(cookies)
|
17
|
21
|
}
|
|
22
|
+
|
|
23
|
+ @Bean
|
|
24
|
+ public CorsConfigurationSource corsConfigurationSource() {
|
|
25
|
+ CorsConfiguration configuration = new CorsConfiguration();
|
|
26
|
+ configuration.addAllowedOrigin("*"); // 允许所有域名访问,也可以指定特定的域名
|
|
27
|
+ configuration.addAllowedMethod("*"); // 允许所有HTTP方法
|
|
28
|
+ configuration.addAllowedHeader("*"); // 允许所有请求头
|
|
29
|
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
30
|
+ source.registerCorsConfiguration("/**", configuration);
|
|
31
|
+ return source;
|
|
32
|
+ }
|
18
|
33
|
}
|