1、引入pom依赖包

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>

2、配置application.application

# spring session使用存储类型
spring.session.store-type=redis

#配置redis集群

spring.redis.cluster.nodes=192.168.1.55:7000,192.168.1.53:7003

3、启动类中增加@EnableRedisHttpSession

4、使用
request.getSession().setAttribute(“username”, “admin”);
String userName = (String) request.getSession().getAttribute(“username”);