本文主要是介绍java.lang.IllegalArgumentException: When allowCredentials is true,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.遇到的错误
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.
2.解决办法
因为调整了springboot-3.3.0版本,查了下需要修改参数allowedOriginPatterns。
@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("*");
}
}
这篇关于java.lang.IllegalArgumentException: When allowCredentials is true的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!