SpringBoot实现Session共享

一、创建项目并导入依赖

   

<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>

   

二、相关配置和代码

   

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

   

   

三、打包测试

   

双击打包,注意打包时把test跳过,点那个闪电就可以跳过测试

   

在cmd中运行第一个项目

   

   

使用新版redis必须导入security,security访问项目时需要登陆,用户名user密码

控制台复制

   

再在cmd运行第二个项目

   

   

   

效果图

   

   

猜你喜欢

转载自www.cnblogs.com/fernfei/p/12128013.html
今日推荐