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 高可用流量管理框架:以流量為切入點,限流、流量整形、熔斷降級、系統負載保護、熱點防護
