- 添加依赖
pom.xml
<!-- 使用 spring-session-data-redis -->
<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>
- 配置文件
application.yml
spring:
session:
store-type: redis
redis:
namespace: spring:session
flush-mode: on_save
redis:
host: localhost
database: 0
port: 6379
SecurityContextPersistenceFilter.java
过滤器中 HttpSessionSecurityContextRepository
将会从redis中获取信息。