gateway 跨域问题解决方案
作者:互联网
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.addAllowedHeader("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
}
2. 配置 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: '*'
一:springcloud服务 --------------------------------------www.fhadmin.org------------------------
1.nacos 阿里注册中心:官方eureka停止更新,目前比较好的取代者就是nacos
2.zipkin 跟踪服务:分布式跟踪日志,基于内存存储记录
3.gateway 网关路由服务:分发请求,统一管理过滤,结合 ribbon 负载均衡、feign服务调用
4.springboot-admin 监控中心服务:统一界面管理,查看各个服务运行状态 actuator健康检查
5.sentinel 高可用流量管理框架:以流量为切入点,限流、流量整形、熔断降级、系统负载保护、热点防护
标签:corsConfigurations,跨域,解决方案,springframework,org,import,config,gateway 来源: https://www.cnblogs.com/sjingser1/p/14852755.html