亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

SpringBoot 如何實現Session共享

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

HttpSession,是通過Servlet容器創建并進行管理的,創建成功以后將會保存在內存中,這里將會使用Redis解決session共享的問題。

創建項目

SpringBoot 如何實現Session共享

添加pom

添加相關的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

創建Controller用來執行測試操作

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 負載均衡

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

請求分發

保存數據

SpringBoot 如何實現Session共享

獲取數據

SpringBoot 如何實現Session共享

以上就是SpringBoot 如何實現Session共享的詳細內容,更多關于SpringBoot 實現Session共享的資料請關注好吧啦網其它相關文章!

標簽: Spring
相關文章:
主站蜘蛛池模板: 日韩国产三级 | 51国产偷自视频区视频手机播器 | 亚洲人成网站色7799在线观看 | 精品国产一区二区二三区在线观看 | 精品国产日韩亚洲一区二区 | 日韩在线视频中文字幕 | 自拍一页| 三级黄色毛片视频 | 三级黄色在线观看 | 在线欧美精品二区三区 | 亚洲欧美激情在线 | 亚洲天堂久久精品成人 | 一级色网站 | 加勒比久久综合 | 亚洲人免费视频 | 日本一区三区二区三区四区 | 日本九六视频 | 国产精品1页 | 中文在线三级中文字幕 | 免费区欧美一级毛片精品 | 日本免费一区二区三区三州 | 一级特色大黄美女播放网站 | 午夜私人影院免费体验区 | 亚洲一区免费在线 | 免费人成黄页网站在线观看国产 | 亚洲精品在线视频观看 | 草草草在线观看 | japanese色系国产在线高清 | 亚洲欧美综合久久 | 亚洲精品aaa| 中文字幕1区 | 毛片中文字幕 | 中文字幕99在线精品视频免费看 | 毛片一级做a爰片性色 | 日韩freesex呦交 | 成年人网站免费 | 国模肉肉人体大尺度啪啪 | 一级成人毛片 | 国产欧美成人xxx视频 | 欧美性精品hd在线观看 | 精品亚洲成a人在线观看 |