foreword
Earlier we integrated Redis into the project, and now we need to use it to do something practical. This time, in order to solve the problem of session sharing in the distributed system, the session is hosted in Redis.
text
import dependencies
In addition to the introduction in the previous article, dependenciesspring-boot-starter-data-redis
are also required :spring-session
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
configure
In the system configuration file add:
spring:
session:
store-type: redis
And it can be found that store-type
there are several values that can be set, all of which can be used as a medium for session sharing.
As you can see, Spring Session supports the use of Redis, Mongo, JDBC, and Hazelcast to store Sessions.
This is done.
test
It can be seen that the session has been taken over by shiro.
The idea of spring-session implementation is : design a Filter, use HttpServletRequestWrapper
, implement your own, getSession()方法
and take over the work of creating and managing Session data.