1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      SpringBoot中怎么解決跨域請(qǐng)求問題

      今天就跟大家聊聊有關(guān)Spring Boot 中怎么解決跨域請(qǐng)求問題,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

      創(chuàng)新互聯(lián)主要從事成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)寶興,十余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792

      解決方法

      跨域問題可以在前端解決也可以在后端解決,我個(gè)人覺得在后端解決更方便一些。

      只需要添加一個(gè)配置類。

      package com.example.demo.config;
      
      import org.springframework.context.annotation.Configuration;
      import org.springframework.web.servlet.config.annotation.CorsRegistry;
      import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
      
      @Configuration
      public class CorsConfig implements WebMvcConfigurer {
          @Override
          public void addCorsMappings(CorsRegistry registry) {
              registry.addMapping("/**")
                      .allowedOriginPatterns("*")
                      .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                      .allowCredentials(true)
                      .maxAge(3600)
                      .allowedHeaders("*");
          }
      }

      在本項(xiàng)目中,我的源碼放在com.example.demo包下,在這個(gè)包中新建一個(gè)包,放入該配置類,即可解決跨域問題。

      注意allowedOriginPatterns()方法不要用allowedOrigins(),不然項(xiàng)目運(yùn)行時(shí)請(qǐng)求后端接口會(huì)報(bào)錯(cuò)。

      org.springframework.beans.factory.BeanCreationException: 
      Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; 
      nested exception is java.lang.IllegalArgumentException: 
      When allowCredentials is true, allowedOrigins cannot contain the special value "*"since that cannot be set on the "Access-Control-Allow-Origin" response header. 
      To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

      看完上述內(nèi)容,你們對(duì)Spring Boot 中怎么解決跨域請(qǐng)求問題有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。


      分享文章:SpringBoot中怎么解決跨域請(qǐng)求問題
      文章源于:http://www.ef60e0e.cn/article/pohdig.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        简阳市| 黄冈市| 香河县| 资中县| 浦江县| 苍山县| 陇西县| 且末县| 宁安市| 临邑县| 濮阳市| 砀山县| 萨迦县| 洱源县| 饶河县| 象山县| 渭南市| 延庆县| 磴口县| 区。| 达州市| 华蓥市| 神池县| 二连浩特市| 隆化县| 乡宁县| 天津市| 永修县| 星子县| 永善县| 花莲县| 都昌县| 北碚区| 廉江市| 合作市| 荃湾区| 自贡市| 宣恩县| 宣武区| 三门县| 拉萨市|