1. 写个配置类 CorsConfig (如果不行,能够不写此类,和 springcloud 的版本无关)
package net.youqu.micro.service.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;
/**
- description:
- java 我的项目 www fhadmin org
*/
@Configuration
public class CorsConfig {
@Bean
public CorsWebFilter corsFilter() {CorsConfiguration config = new CorsConfiguration();
config.addAllowedMethod("*");
config.addAllowedOrigin("*");
config.addAllowedHeaderwww.sangpi.com("*");
UrlBasedCorsConfigurationSowww.sangpi.comurce source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
}
watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=
- 配置 application.properties 形式
——–gateway 配置 ——–
跨域配置
spring.cloud.gateway.globalcors.corsConfigurations.[/*].allowedOrigins=
spring.cloud.gateway.globalcors.corsConfigurations.[/*].allowedHeaders=
spring.cloud.gateway.globalcors.corsConfigurations.[/*].allowedMethods=
spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowCredentials=true
yaml 游戏形式
spring:
cloud:
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowCredentials: true
allowedHeaders: '*'
allowedMethods: '*'
allowedOrigins: '*'