av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

SpringBoot 如何實現Session共享

瀏覽:4日期: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
相關文章:
主站蜘蛛池模板: 成人午夜精品一区二区三区 | 亚洲精品乱码久久久久久按摩观 | 欧美久久视频 | 免费h在线 | 日本国产一区二区 | 欧美日韩亚洲国产 | 日韩午夜精品 | av一区二区三区四区 | 日日操av | 国产精品久久久久久久久久了 | 国产精品福利一区二区三区 | 日日想夜夜操 | 国产精品一区三区 | 久久成人在线视频 | 91免费在线视频 | 日本不卡免费新一二三区 | www.一区二区三区 | 成在线人视频免费视频 | 日本三级日产三级国产三级 | 日本免费一区二区三区 | 一区二区三区在线播放视频 | 亚洲精品一区二区在线观看 | 精品久久久久久久久久久院品网 | 亚洲精品一区二三区不卡 | 久草免费在线视频 | 欧美日韩高清免费 | 99精品一区二区 | 国产一区二区免费在线 | 91美女在线观看 | 国产在线精品一区二区三区 | 很很干很很日 | 成人中文字幕在线观看 | 亚洲精品在线看 | 国产福利资源 | 在线播放中文字幕 | 人和拘一级毛片c | av大全在线 | 超碰在线播| jⅰzz亚洲| 国产午夜精品久久久 | www亚洲精品 |