Prerequisite: You need to use Redis for session storage
1. Introduction of Spring-session-data-redis Package
<!--Redis-->
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-redis</artifactid>
</dependency>
<!--spring-session--
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
Note: The purpose of this package is to refer the session to Redis management
[Email protected]/@EnableSpringHttpSession
The startup class needs to add the annotation @enableredishttpsession, which identifies enabling Redis storage HttpSession
3. Configure Redis
# Redis Cluster
spring.redis.cluster.nodes= 192.168.3.208:7001,192.168.3.208:7002,192.168.3.208:7003,192.168.3.208:7004,192.168.3.208:7005,192.168.3.208:7006
# single Redis with cluster two on top select one
Spring.redis.host=localhost
# # Connection pool Maximum number of connections (use negative values to indicate no limit)
spring.redis.pool.max-active=300
# # Redis Database index (default = 0)
spring.redis.database=0
# # Connection pool maximum blocking wait time (use negative value to indicate no limit)
Spring.redis.pool.max-wait=-1
# # Maximum idle connections in the connection pool
spring.redis.pool.max-idle=100
# # Minimum idle connections in the connection pool
spring.redis.pool.min-idle=20
# # Connection time-out (milliseconds)
spring.redis.timeout=60000
After Redis and session have been configured, the HttpSession information for each service is shared in the same Redis cache after using the distributed multi-server application.
Springboot session sharing (using Redis)