Spring Boot + Redis 集成
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>1.37.0</version>
</dependency>
<!-- Sa-Token 整合 Redis (使用 jackson 序列化方式) -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
<version>1.37.0</version>
</dependency>
<!-- 提供Redis连接池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
sa-token:
# token 名称(同时也是 cookie 名称)
token-name: satoken
# token前缀
token-prefix: Brear
# token 有效期(单位:秒) 默认30天,-1 代表永久有效
timeout: 2592000
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
active-timeout: -1
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
is-concurrent: true
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
is-share: true
# 同一账号最大登录数量,-1代表不限 (只有在 isConcurrent=true,isShare=false 时此配置才有效
max-login-count: 2
# token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
token-style: random-32
# 是否输出操作日志
is-log: true
# 是否打开自动续签,为true框架会在每次直接或间接调用getLoginId()时进行一次过期检查和续签操作
autoRenew: true
# 是否尝试从cookie中读取token 此值为false StpUtils.login()登录时也不会往前端注入cookie
is-read-cookie: false
spring:
# redis配置
redis:
# Redis数据库索引
database: 1
# Redis服务器地址
host: 127.0.0.1
# 密码
password:
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码(默认为空)
# password:
# 连接超时时间
timeout: 10s
lettuce:
pool:
# 连接池最大连接数
max-active: 200
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
# 连接池中的最大空闲连接
max-idle: 10
# 连接池中的最小空闲连接
min-idle: 0
StpUtil.login()
StpUtil.getTokenInfo()
拦截器方式
@Configuration
public class