[转]When allowCredentials is true, allowedOrigins cannot contain the special value “*“

前言

  项目接口访问出现allowedOrigins cannot contain the special value "*"

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.

修改方式

修改allowedOriginsallowedOriginPatterns

(1)修改前:

复制代码
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
            .allowCredentials(true)
            .maxAge(3600)
            .allowedHeaders("*");
}
复制代码

(2)修改后:

复制代码
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOriginPatterns("*")
            .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
            .allowCredentials(true)
            .maxAge(3600)
            .allowedHeaders("*");
}
复制代码

原文链接:When allowCredentials is true, allowedOrigins cannot contain the special value “*“

posted @   rainbow70626  阅读(699)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2020-12-17 [转]C#从MySQL数据库中读取
2020-12-17 [转]关于c#中遍历从数据库中取出的DataTable集合
2017-12-17 用VS2012或VS2013在win7下编写的程序在XP下运行就出现“不是有效的win32应用程序
2016-12-17 ASP.NET MVC - 探究应用程序文件夹
2016-12-17 ASP.NET MVC - 创建Internet 应用程序
2016-12-17 ASP.NET MVC 教程-MVC简介
点击右上角即可分享
微信分享提示