Springboot跨域配置报错:When allowCredentials is true, allowedOrigins cannot contain the specia
错误信息为:
When allowCredentials is true, allowedOrigins cannot contain thespecial 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.
大概意思是:allowCredentials为true时,allowedOrigins不能包含特殊值“*”,因为不能在“Access Control Allow Origin”响应头上设置该值。要允许凭据指向一组源,请显式列出它们,或者考虑改用“allowedOriginPatterns”。
所以解决办法:将.allowedOrigins
替换成.allowedOriginPatterns
即可。
修改前:
//全局配置类--配置跨域请求
@Configuration
public class CrosConfig implements WebMvcConfigurer {static final String ORIGINS[] = new String[]{"GET", "POST", "PUT", "DELETE","OPTIONS"};@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**") // 所有的当前站点的请求地址,都支持跨域访问。.allowedOrigins("*") // 所有的外部域都可跨域访问。 如果是localhost则很难配置,因为在跨域请求的时候,外部域的解析可能是localhost、127.0.0.1、主机名.allowCredentials(true) // 是否支持跨域用户凭证.allowedMethods(ORIGINS) // 当前站点支持的跨域请求类型是什么.maxAge(3600); // 超时时长设置为1小时。 时间单位是秒。}
}
该版本用于springboot2.0.0中
修改后:
//全局配置类--配置跨域请求
@Configuration
public class CrosConfig implements WebMvcConfigurer {static final String ORIGINS[] = new String[]{"GET", "POST", "PUT", "DELETE","OPTIONS"};@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**") // 所有的当前站点的请求地址,都支持跨域访问。.allowedOriginPatterns("*") // 所有的外部域都可跨域访问。 如果是localhost则很难配置,因为在跨域请求的时候,外部域的解析可能是localhost、127.0.0.1、主机名.allowCredentials(true) // 是否支持跨域用户凭证.allowedMethods(ORIGINS) // 当前站点支持的跨域请求类型是什么.maxAge(3600); // 超时时长设置为1小时。 时间单位是秒。}
}
该版本用于springboot2.4.0中
Springboot跨域配置报错:When allowCredentials is true, allowedOrigins cannot contain the specia相关推荐
- When allowCredentials is true, allowedOrigins cannot contain the specia 跨域 网关跨域
解决办法:跨域配置报错,将.allowedOrigins替换成.allowedOriginPatterns即可. SpringBoot2.0.0中 @Configuration public clas ...
- 跨域 问题:When allowCredentials is true, allowedOrigins cannot contain the specia
解决办法:跨域配置报错,将.allowedOrigins替换成.allowedOriginPatterns即可. 修改前 @Configuration public class WebMvcConfi ...
- SpringBoot升级2.4.0所出现的问题:When allowCredentials is true, allowedOrigins cannot contain the specia
When allowCredentials is true, allowedOrigins cannot contain the special value "*"since th ...
- 【SpringBoot】升级2.4.0所出现的问题:When allowCredentials is true, allowedOrigins cannot contain the specia
项目场景: 提示:这里简述项目相关背景: 保留现场: When allowCredentials is true, allowedOrigins cannot contain the special ...
- SpringBoot升级所出现的问题:When allowCredentials is true, allowedOrigins cannot contain the specia
错误信息如下 When allowCredentials is true, allowedOrigins cannot contain the special value "*" ...
- Springboot 跨域配置
访问后端接口遇到错误提示: When allowCredentials is true, allowedOrigins cannot contain the special value "* ...
- springboot 跨域配置cors
撸了今年阿里.头条和美团的面试,我有一个重要发现.......>>> 1 跨域的理解 跨域是指:浏览器A从服务器B获取的静态资源,包括Html.Css.Js,然后在Js中通过Ajax ...
- 【跨域】跨域原理 + springboot跨域配置(万能版)
先上配置 这个配置是个万能药,配上之后就没有任何跨域问题了. @Configuration public class MvcConfig implements WebMvcConfigurer {@B ...
- 报错:uni-app跨域请求报错
编辑器:HBuilderX 语言架构:uni-app + uview+ luch-Request 报错情况:本地运行后端 jar 包,列表页面访问没有问题,打开子组件详情页却跨域错误.但是换台电脑的情 ...
最新文章
- 博客开通第一天,加油
- 科技垄断正在朝着纵向发展
- .NET零基础入门06:面向对象入门
- Mac 设置文件默认打开方式
- 较复杂js的书写格式
- MFC创建单文档工程(左上角名称前的mfc图标修改为其他需求图标)
- Matplotlib 可视化之箭头与标注的高级应用
- g++ vscode 环境选择_Visual Studio Code 配置C/C++环境
- 类的加载过程三:Initialization
- 桩筏有限元中的弹性板计算_PKPM2010年11月结构技术问题汇总
- Lucas+阶乘打表+费马小定理模板2.0
- 使用半透明的DIV实现禁用页面功能
- 无比强悍的CRM营销模块,SuiteCRM功能介绍
- html拾色器没效果,用html和js写一个拾色器
- XCTF-攻防世界-密码学crypto-新手练习区-writeup
- 单招软件职业技能测试,招生信息网-2019年单独招生《职业技能测试》考试大纲...
- html 中数字一直往上加的动态效果,CSS动画:数字增量效果
- 华为手机html乱码,华为手机语言设置中文
- 剑指Offer:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法
- 蓝桥ROS机器人之C++基础开发第一个程序