Spring Boot采用Shrio的Session时,与WebSocket的会话Session共享与访问。
1.增加WebSocket配置文件
package com.ruoyi.websocket.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.session.StandardSessionFacade;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
/**
* @author liangzhu
* @date 2021年 06月23日 17:48:57
*/
@Configuration
@Slf4j
public class WebsocketConfiguration extends ServerEndpointConfig.Configurator {
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
//获取HttpSessionID
HttpSession httpSession=(HttpSession) request.getHttpSession();