传统捞项目基于servlet容器 cookie单体会话改造分布式会话方案
##引入redis,spring-session依赖
<!--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>
##修改配置文件
spring:
application:
name: hnmop-consumer
session:
timeout: 3600
store-type: redis
redis:
namespace: yym:session
redis:
lettuce:
pool:
max-idle: 50
min-idle: 10
max-wait: 300
max-active: 25
timeout: 30000
cluster:
nodes:
- 192.168.3.156:6379
- 192.168.3.156:6380
- 192.168.3.156:6381
- 192.168.3.156:6382
- 192.168.3.156:6383
- 192.168.3.156:6384
# - redis-service.hdsst-ns.svc.cluster.local:6379
# - redis-service.hdsst-ns.svc.cluster.local:6379
# - redis-service.hdsst-ns.svc.cluster.local:6379
# - redis-service.hdsst-ns.svc.cluster.local:6379
# - redis-service.hdsst-ns.svc.cluster.local:6379
# - redis-service.hdsst-ns.svc.cluster.local:6379
password: 123456
database: 0
##启动类加入EnableRedisHttpSession注解
@EnableRedisHttpSession(redisNamespace = "yym:session", maxInactiveIntervalInSeconds = 3600)
##原理
##spring自动配置spring.factories
##生成SessionRepositoryFilter过滤器对象
##使用包装的SessionRepositoryRequestWrapper的request?? SessionRepositoryResponseWrapper的response