怎樣解決springcloud alibaba gateway跨域問(wèn)題,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
博樂(lè)網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,博樂(lè)網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為博樂(lè)千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的博樂(lè)做網(wǎng)站的公司定做!
1.寫個(gè)配置類CorsConfig (如果不行,可以不寫此類,和springcloud的版本有關(guān))
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項(xiàng)目www.fhadmin.org */@Configurationpublic class CorsConfig {@Beanpublic 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: trueallowedHeaders: '*'allowedMethods: '*'allowedOrigins: '*'
看完上述內(nèi)容,你們掌握怎樣解決springcloud alibaba gateway跨域問(wèn)題的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!