午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

SpringBoot 如何實現Session共享

瀏覽:14日期: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
相關文章:
主站蜘蛛池模板: 精品在线小视频 | 久久久久久久久久久久久久 | 久久午夜国产精品 | 午夜天堂在线 | 找国产毛片看 | 亚洲免费视频网站 | 9.1人成人免费视频网站 | 日韩一道本 | 亚洲欧美日本一区 | av中文资源 | 亚洲午夜精品久久久久久高潮 | 日韩一区三区 | 一区二区中文 | 婷婷俺来也 | 天天色播| 色综合天天综合网国产成人网 | 国产久精品 | 色综合天天综合网天天狠天天 | 国产免费观看av | 欧美精品aaa | 香蕉视频免费在线播放 | 亚洲成人久久久 | 天堂网av手机版 | 日韩色在线 | 夜夜操天天 | 欧美日韩亚洲天堂 | 日韩欧美国产一区二区三区 | 在线观看黄色 | 香蕉在线影院 | 神马午夜影院 | 亚洲欧美在线观看视频 | 超碰国产在线 | 蜜桃天堂| 欧美一级做性受免费大片免费 | 欧美黄色精品 | 国产日本一区二区 | 亚洲精品福利视频 | 色爽女| 自拍偷拍 亚洲 | 欧美中文日韩 | 久操av|