Bootstrap

解决Springboot2.X,无法用HttpSession报错org.apache.tomcat.websocket.server.WsSessionListener.sessionCreated

一、今天在学习 springboot2.x 拦截器的时候,发现直接使用 HttpSession 和 request.getSession().getAttribute() 会直接报错;

我的springboot2.x 版本:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.4</version>
        <relativePath/> <!-- lookup parent from repository -->
</parent>

1、异常信息如下:

java.lang.AbstractMethodError: org.apache.tomcat.websocket.server.WsSessionListener.sessionCreated(Ljavax/servlet/http/HttpSessionEvent;)V

2、看异常大概是 session 无法创建;解决方法就是添加 redis 依赖和 spring session依赖,直接上代码:

2-1、pom.xml 添加 redis 依赖和 spring session依赖

<!--添加 Redis 整合 springboot 依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
;