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運行第二個項目

   

   

   

效果圖

   

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM