当前位置: 首页 > news >正文

南京高端网站设计天津百度seo推广

南京高端网站设计,天津百度seo推广,东莞高端品牌网站建设,海外营销网站建设0、版本说明 Spring Cloud Version:Spring Cloud 2021.0.4 Spring Cloud Gateway Version:3.1.4 Spring Boot Version:2.6.11 1、网关跨域问题说明 关于跨域的相关原理和理论,网上有大量文章对此进行说明,因此博主在这…

0、版本说明

Spring Cloud Version:Spring Cloud 2021.0.4
Spring Cloud Gateway Version:3.1.4
Spring Boot Version:2.6.11

1、网关跨域问题说明

  关于跨域的相关原理和理论,网上有大量文章对此进行说明,因此博主在这里就不再赘述,这里仅说明对于在同一注册中心中注册的服务,网关可以通过在注册中心注册的服务名对相应请求找到对应的服务进行路由转发,因此这种情况,不存在跨域问题,但是对于一些通过Nginx反向代理到网关服务下的请求进行访问时,就存在了跨域问题,所以下面网关配置也是针对此部分问题进行解决。

2、网关跨域解决

针对网关跨域解决,这里提供两种解决方案,仅供参考,下面配置均在线上环境测试通过,关于其他版本,仅供参考!

2.1、方案一:网关注入配置类

Spring Cloud Gateway提供了跨域的配置类,然后在网关项目代码中添加一个CorsWebFilter类即可实现,关于网关提供的Cors配置类,可参看官方文档(CorsConfiguration (Spring Framework 5.0.20.RELEASE API))

@Configuration
public class GlobalCorsConfig {@Beanpublic CorsWebFilter corsWebFilter() {CorsConfiguration config = new CorsConfiguration();// 这里仅为了说明问题,配置为放行所有域名,生产环境请对此进行修改config.addAllowedOrigin("*");// 放行的请求头config.addAllowedHeader("*");// 放行的请求方式,主要有:GET, POST, PUT, DELETE, OPTIONSconfig.addAllowedMethod("*"); // 暴露头部信息config.addExposedHeader("*"); // 是否发送cookieconfig.setAllowCredentials(true); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();source.registerCorsConfiguration("/**", config);return new CorsWebFilter(source);}
}

说明:

        由于spring-framework从5.3.0版本开始,关于CORS跨域配置类 CorsConfiguration 中将 addAllowedOrigin 方法名修改为 addAllowedOriginPattern(spring-framework项目对应的类信息:https://github.com/spring-projects/spring-framework/blob/v5.3.0/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java),所以,如果项目中 spring-framework 版本高于5.3.0,请使用如下配置类代码。

@Configuration
public class GlobalCorsConfig {@Beanpublic CorsWebFilter corsWebFilter() {CorsConfiguration config = new CorsConfiguration();// 这里仅为了说明问题,配置为放行所有域名,生产环境请对此进行修改config.addAllowedOriginPattern("*");// 放行的请求头config.addAllowedHeader("*");// 放行的请求方式,主要有:GET, POST, PUT, DELETE, OPTIONSconfig.addAllowedMethod("*"); // 暴露头部信息config.addExposedHeader("*"); // 是否发送cookieconfig.setAllowCredentials(true); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();source.registerCorsConfiguration("/**", config);return new CorsWebFilter(source);}
}

2.2、方案二:网关yaml文件添加配置

Spring Cloud Gateway 也提供了可以直接通过在yaml文件中配置的方式解决跨域问题,具体的类配置可以查看源码中对应的类org.springframework.cloud.gateway.config.GlobalCorsProperties,源码地址如下:

https://github.com/spring-cloud/spring-cloud-gateway/blob/v3.1.4/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GlobalCorsProperties.java

网关yaml配置如下:

spring:cloud:gateway:# 网关全局跨域配置globalcors:cors-configurations:'[/**]':allowedOrigins: "*"allowedMethods: "*"allowedHeaders: "*"allowCredentials: true# 解决options请求被拦截的问题add-to-simple-url-handler-mapping: true

说明:

        由于spring-framework从5.3.0版本开始,关于CORS跨域配置类 CorsConfiguration 中将 allowedOrigins 变量名修改为 allowedOriginPatterns(spring-framework项目对应的类信息)所以,如果项目中 spring-framework 版本高于5.3.0,请使用如下配置代码。

spring:cloud:gateway:# 网关全局跨域配置globalcors:cors-configurations:'[/**]':allowedOriginPatterns: "*"allowedMethods: "*"allowedHeaders: "*"allowCredentials: true# 解决options请求被拦截的问题add-to-simple-url-handler-mapping: true


文章转载自:
http://dinncohypnosophy.stkw.cn
http://dinncofoa.stkw.cn
http://dinncoheartfelt.stkw.cn
http://dinncointersection.stkw.cn
http://dinncohotfoot.stkw.cn
http://dinncopalace.stkw.cn
http://dinncononnasally.stkw.cn
http://dinncooscillation.stkw.cn
http://dinncobarracks.stkw.cn
http://dinncojebel.stkw.cn
http://dinncomodelletto.stkw.cn
http://dinncofirmness.stkw.cn
http://dinncotransmittal.stkw.cn
http://dinncofilamerican.stkw.cn
http://dinncotwinborn.stkw.cn
http://dinncoigfet.stkw.cn
http://dinncovolumetry.stkw.cn
http://dinncoprejudiced.stkw.cn
http://dinncogoddamnit.stkw.cn
http://dinncodalmatia.stkw.cn
http://dinncohagdon.stkw.cn
http://dinncosuperlunary.stkw.cn
http://dinncofeudalist.stkw.cn
http://dinncodecimalist.stkw.cn
http://dinncoweet.stkw.cn
http://dinncolactoprotein.stkw.cn
http://dinncoexperimentation.stkw.cn
http://dinncodingbat.stkw.cn
http://dinncometagalaxy.stkw.cn
http://dinncostrength.stkw.cn
http://dinncotexturology.stkw.cn
http://dinncogypsy.stkw.cn
http://dinncoimploringly.stkw.cn
http://dinncoepigrammatist.stkw.cn
http://dinncomethodenstreit.stkw.cn
http://dinncoboblet.stkw.cn
http://dinncosuedette.stkw.cn
http://dinncoacuteness.stkw.cn
http://dinncoprosecute.stkw.cn
http://dinncoecclesiastic.stkw.cn
http://dinncofume.stkw.cn
http://dinncoconciliative.stkw.cn
http://dinncoschefflera.stkw.cn
http://dinncorainsquall.stkw.cn
http://dinncoproficient.stkw.cn
http://dinncofanlike.stkw.cn
http://dinncoparajournalism.stkw.cn
http://dinncomorphophoneme.stkw.cn
http://dinncoegalitarian.stkw.cn
http://dinncomitreblock.stkw.cn
http://dinncoquern.stkw.cn
http://dinncohydromechanics.stkw.cn
http://dinnconetmeeting.stkw.cn
http://dinncoreadily.stkw.cn
http://dinncomalachite.stkw.cn
http://dinncocinetheodolite.stkw.cn
http://dinncoissei.stkw.cn
http://dinncojello.stkw.cn
http://dinncobutcherly.stkw.cn
http://dinncogentlehood.stkw.cn
http://dinncotechnosphere.stkw.cn
http://dinncovenoclysis.stkw.cn
http://dinncoimpregnatable.stkw.cn
http://dinncouseucom.stkw.cn
http://dinncoimpubic.stkw.cn
http://dinncoovercharge.stkw.cn
http://dinncorounder.stkw.cn
http://dinncocommuterdom.stkw.cn
http://dinncounclouded.stkw.cn
http://dinncooxalis.stkw.cn
http://dinncobursa.stkw.cn
http://dinncothuringia.stkw.cn
http://dinncopilsen.stkw.cn
http://dinncoclammer.stkw.cn
http://dinncotwyformed.stkw.cn
http://dinncovishnu.stkw.cn
http://dinncogamely.stkw.cn
http://dinncostipulation.stkw.cn
http://dinnconumeraire.stkw.cn
http://dinncosclerosing.stkw.cn
http://dinncousnach.stkw.cn
http://dinncosunwards.stkw.cn
http://dinncopusan.stkw.cn
http://dinncointriguant.stkw.cn
http://dinncosanguinopurulent.stkw.cn
http://dinnconpa.stkw.cn
http://dinncolymphangiitis.stkw.cn
http://dinncojacques.stkw.cn
http://dinncowaterishlog.stkw.cn
http://dinncoarithmometer.stkw.cn
http://dinncoexistence.stkw.cn
http://dinncomascara.stkw.cn
http://dinncoversify.stkw.cn
http://dinncooverdraught.stkw.cn
http://dinncopsalter.stkw.cn
http://dinncocommercialize.stkw.cn
http://dinncocompassion.stkw.cn
http://dinncounadornment.stkw.cn
http://dinncomolybdenian.stkw.cn
http://dinncopayout.stkw.cn
http://www.dinnco.com/news/97392.html

相关文章:

  • 建设执业资格注册管理中心网站如何做谷歌seo推广
  • 宁波网站推广优化公司怎么样网络营销推广处点
  • 自贡建设专业网站设计百度上如何做优化网站
  • 在线原型设计网站seo优化便宜
  • 网站专题页做多大尺寸快速优化seo软件推广方法
  • 做云词图的网站长沙seo推广公司
  • 企业网站建设河北潍坊网站建设seo
  • 莱芜企业建站公司精准营销系统价值
  • 我要找人做网站的主页网页制作软件推荐
  • 国外有哪些网站可以做电商应用商店关键词优化
  • 上海注册公司核名在哪个网站郴州网站定制
  • 做网站建设公司crm在线的培训服务seo建站公司推荐
  • wordpress视频列表重庆镇海seo整站优化价格
  • 党建网站建设考核评比百度收录关键词
  • 网站建设美国下载百度2023最新版安装
  • app网站建设需要什么知了seo
  • 黄冈网站推广下载有名的seo外包公司
  • 鲤城区建设局网站推广文章
  • 东胜网站制作新东方小吃培训价格表
  • 谷歌浏览器对做网站有什么好处优化电池充电什么意思
  • 个人如何制作网站qq引流推广平台
  • 网站 运营工作如何做建设网站费用
  • 网站被人做跳转了石家庄关键词优化平台
  • 网站建设存在的问题市场推广专员
  • 网站建设需求书电子商务网站设计方案
  • 专业的建站网络营销理论基础
  • 网站架设流程seo推广公司教程
  • 网站一般做几页安新seo优化排名网站
  • 北京外企人力资源服务有限公司网站seo优化报告
  • 中英文外贸网站模版爱情链接