java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the

后端springboot前端vue,利用websocket实现在线聊天功能

前台浏览器console报错:

websocket.js?13c0:6 WebSocket connection to 'ws://localhost:8080/ws/ep/213/zu1c2zfs/websocket' failed: 

后端报错:

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.

前期疯狂盯着前端报的错找解决方案:试了很多都不管用。
后端开始报这个错也没注意,因为定位到的是java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the_第1张图片
jwt认证过滤器这块,但我其他都没问题,所以没管这个报错。

后面前台报错实在找不到合适的解决办法了,开始盯着这个错去找。
这个错本身也道出了解决方案:onsider using “allowedOriginPatterns” instead.
用 allowedOriginPatterns,我之前用的是setAllowedOrigins(“*”)。

java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the_第2张图片

参考博客

此博主说明是SpringBoot版本的问题。

我的SpringBoot版本2.5.6:

<dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
        <version>2.5.6version>
 dependency>

检查一下学习视频中用到的是SpringBoot版本是2.3.0
在这里插入图片描述

综上解决方案:
springboot版本的原因导致写法变化。
setAllowedOrigins(““) 改成allowedOriginPatterns(””) 。

所以呀一个错都不要放过,浪费了一天多时间。

你可能感兴趣的:(SpringBoot,java,websocket,spring,boot)