When allowCredentials is true, allowedOrigins cannot contain the special value “*“ that cannot be
生活随笔
收集整理的這篇文章主要介紹了
When allowCredentials is true, allowedOrigins cannot contain the special value “*“ that cannot be
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SpringBoot升級2.4.0所出現的問題:
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.
解決方案:
跨域配置報錯,將.allowedOrigins替換成.allowedOriginPatterns即可。
調整前:
調整后:
package com.course.server.config;import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration public class CorsConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {// 設置允許跨域的路由registry.addMapping("/**")// 設置允許跨域請求的域名.allowedOriginPatterns("*").allowedHeaders(CorsConfiguration.ALL)// 設置允許的方法.allowedMethods(CorsConfiguration.ALL)// 是否允許證書(cookies).allowCredentials(true)// 跨域允許時間.maxAge(3600);//1小時內不需要校驗,發送OPTIONS請求} }總結
以上是生活随笔為你收集整理的When allowCredentials is true, allowedOrigins cannot contain the special value “*“ that cannot be的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动端 uniapp 国际化一站式解决方
- 下一篇: uniapp 封装网络请求