|
@@ -5,6 +5,9 @@ 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.CorsRegistry;
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
@@ -13,13 +16,15 @@ import org.springframework.web.filter.CorsFilter;
|
|
|
* @version: V1.0
|
|
|
**/
|
|
|
@Configuration
|
|
|
-public class CorsConfig {
|
|
|
+public class CorsConfig implements WebMvcConfigurer {
|
|
|
+
|
|
|
private CorsConfiguration buildConfig() {
|
|
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
|
|
- corsConfiguration.setAllowCredentials(true);
|
|
|
+// corsConfiguration.setAllowCredentials(true);
|
|
|
corsConfiguration.addAllowedOrigin("*"); //允许任何域名
|
|
|
corsConfiguration.addAllowedHeader("*"); //允许任何头
|
|
|
corsConfiguration.addAllowedMethod("*"); //允许任何方法
|
|
|
+ corsConfiguration.addExposedHeader("Authorization");
|
|
|
return corsConfiguration;
|
|
|
}
|
|
|
|
|
@@ -29,4 +34,13 @@ public class CorsConfig {
|
|
|
source.registerCorsConfiguration("/**", buildConfig()); //注册
|
|
|
return new CorsFilter(source);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addCorsMappings(CorsRegistry registry) {
|
|
|
+ registry.addMapping("/**")
|
|
|
+ .allowedOrigins("*")
|
|
|
+ .allowCredentials(true)
|
|
|
+ .allowedMethods("GET", "POST")
|
|
|
+ .maxAge(3600);
|
|
|
+ }
|
|
|
}
|