色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot 如何實(shí)現(xiàn)Session共享

瀏覽:3日期:2023-04-28 13:27:23

HttpSession,是通過Servlet容器創(chuàng)建并進(jìn)行管理的,創(chuàng)建成功以后將會(huì)保存在內(nèi)存中,這里將會(huì)使用Redis解決session共享的問題。

創(chuàng)建項(xiàng)目

SpringBoot 如何實(shí)現(xiàn)Session共享

添加pom

添加相關(guān)的maven

<?xml version='1.0' encoding='UTF-8'?><project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.3.1.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/io.lettuce/lettuce-core --> <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>6.0.0.M1</version> </dependency> <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.3.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-data-redis --> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>2.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions><exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId></exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>

配置redis連接

配置redis連接

spring: redis: database: 0 host: 106.53.115.12 port: 6379 password: 12345678 jedis: pool: max-active: 8 max-idle: 8 max-wait: -1ms min-idle: 0

創(chuàng)建Controller用來執(zhí)行測試操作

package com.example.demo;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpSession;@RestControllerpublic class HelloController { @PostMapping('/save') public String saveName(String name, HttpSession session){ session.setAttribute('name', name); return '8080'; } @GetMapping('/get') public String getName(HttpSession httpSession){ return httpSession.getAttribute('name').toString(); }}

Nginx 負(fù)載均衡

mingming@xiaoming-pc:~$ sudo apt-get install nginx

修改配置文件

upstream sang.com { server 192.168.0.1:8080 weight = 1; server 192.168.0.2:8080 weight = 1;}server { listen 80; server_name localhost; location / {proxy_pass http://sang.com;proxy_redirect default; }}

請求分發(fā)

保存數(shù)據(jù)

SpringBoot 如何實(shí)現(xiàn)Session共享

獲取數(shù)據(jù)

SpringBoot 如何實(shí)現(xiàn)Session共享

以上就是SpringBoot 如何實(shí)現(xiàn)Session共享的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot 實(shí)現(xiàn)Session共享的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 一级做a爱过程免费视频时看 | 本道久久综合88全国最大色 | 一级特黄aaa大片在 一级特黄aaa大片在线观看 | 亚洲欧美视频在线 | 成人爱爱网站在线观看 | 欧美一级欧美一级在线播放 | 高清色黄毛片一级毛片 | 99久久精品免费看国产一区二区三区 | 一区二区三区欧美视频 | 成人午夜视频免费观看 | 欧美在线视频精品 | 欧美成人亚洲综合精品欧美激情 | 国产成人精品曰本亚洲77美色 | 久久久久亚洲视频 | 国产成人yy精品1024在线 | 手机在线观看黄色网址 | 成人观看视频又黄又免费 | 国产天堂 | 久久久免费的精品 | 夜夜爱夜夜爽夜夜做夜夜欢 | 免费中文字幕在线 | 精品综合 | 日韩精品一级a毛片 | 亚洲理论欧美理论在线观看 | 国产日产高清欧美一区二区三区 | 国产精品久久久久一区二区 | 欧美高h视频 | 在线免费观看日本视频 | 91最新91精品91蝌蚪 | 免费看a级片 | 日韩a毛片免费全部播放完整 | 中文无线乱码二三四区 | 亚洲精品视频在线观看免费 | 成人欧美视频在线观看播放 | 一级毛片免费观看久 | 天天都色 | 国产高清毛片 | 免费aa在线观看 男人的天堂 | 日本在线视频免费看 | 日一区二区| 国产精品香蕉一区二区三区 |