详细报错信息:

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.

at org.springframework.web.cors.CorsConfiguration.validateAllowCredentials(CorsConfiguration.java:473)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)

前后台报错信息如图所示:

造成问题的原因及解决方案:

当allowCredentials为true时,allowedOrigins不能包含特殊值"*",因为它不能在"Access-Control-Allow-Origin"响应头中设置。 要允许凭证指向一组起源,可以显式地列出它们,或者考虑使用“allowedOriginPatterns”代替。  

参考官网:Web on Servlet Stackicon-default.png?t=M276https://docs.spring.io/spring-framework/docs/5.3.16/reference/html/web.html#mvc-cors-global-java


Thanks

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐