SpringBoot achieve Session Sharing

First, create a project and import dependence

   

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-redis-reactive</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-security</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.session</groupId>

<artifactId>spring-session-data-redis</artifactId>

</dependency>

   

Second, the relevant configuration and code

   

Application.properies

   

spring.redis.database=0

spring.redis.password=fernfei

spring.redis.host=192.168.21.130

spring.redis.port=6379

   

   

server.port=8080

   

   

Controller layer

   

   

Third, the packaging test

   

Double-click the package, pay attention to packaging the test to skip the point that lightning can skip test

   

The first project run in cmd

   

   

Redis must use the new import security, access security needs when landing the project, the user name user password

Console Copy

   

The second project run in cmd

   

   

   

Renderings

   

   

Guess you like

Origin www.cnblogs.com/fernfei/p/12128013.html