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
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
SpringBoot升級2.4.0所出現(xiàn)的問題:
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.
解決方案:
跨域配置報(bào)錯(cuò),將.allowedOrigins替換成.allowedOriginPatterns即可。
調(diào)整前:
調(diào)整后:
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) {// 設(shè)置允許跨域的路由registry.addMapping("/**")// 設(shè)置允許跨域請求的域名.allowedOriginPatterns("*").allowedHeaders(CorsConfiguration.ALL)// 設(shè)置允許的方法.allowedMethods(CorsConfiguration.ALL)// 是否允許證書(cookies).allowCredentials(true)// 跨域允許時(shí)間.maxAge(3600);//1小時(shí)內(nèi)不需要校驗(yàn),發(fā)送OPTIONS請求} }總結(jié)
以上是生活随笔為你收集整理的When allowCredentials is true, allowedOrigins cannot contain the special value “*“ that cannot be的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动端 uniapp 国际化一站式解决方
- 下一篇: uniapp 封装网络请求