项目场景:
Spring boot websocket 所遇到的一些问题记录
问题描述以及解决方法
一.Springboot websocket jar包版本有些区别,在配置config中允许跨域问题,旧版本只能用.setAllowedOrigins(““),新jar包有.setAllowedOrigins(””)和.setAllowedOriginPatterns(““)两个,一般用.setAllowedOriginPatterns(””),setAllowedOrigins(“*”)加.withSockJS()这个可能会导致
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.
Springboot websocket jar包版本与spring-boot-starter-parent版本有关,我用的是2.7.10这个版本
二,websocket 项目本地测试链接没问题,但部署远程链接不上,原因是没有配内网穿透
location {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
—}