传统捞项目基于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文章来源:https://www.toymoban.com/news/detail-771065.html
文章来源地址https://www.toymoban.com/news/detail-771065.html
到了这里,关于传统项目基于tomcat cookie单体会话升级分布式会话解决方案的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!