最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年09月03日 09:34:17   作者:mySoul  
這篇文章主要介紹了SpringBoot 如何實(shí)現(xiàn)Session共享,幫助大家更好的理解和學(xué)習(xí)spring boot框架,感興趣的朋友可以了解下

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

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

添加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用來(lái)執(zhí)行測(cè)試操作

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;

@RestController
public 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;
    }

}

請(qǐng)求分發(fā)

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

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

以上就是SpringBoot 如何實(shí)現(xiàn)Session共享的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot 實(shí)現(xiàn)Session共享的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 提示:Decompiled.class file,bytecode version如何解決

    提示:Decompiled.class file,bytecode version如何解決

    在處理Decompiled.classfile和bytecodeversion問(wèn)題時(shí),通過(guò)修改Maven配置文件,添加阿里云鏡像并去掉默認(rèn)鏡像,解決了下載源的問(wèn)題,同時(shí),檢查并修改了依賴版本,確保了問(wèn)題的解決
    2024-12-12
  • JavaWeb開(kāi)發(fā)入門第二篇Tomcat服務(wù)器配置講解

    JavaWeb開(kāi)發(fā)入門第二篇Tomcat服務(wù)器配置講解

    JavaWeb開(kāi)發(fā)入門第二篇主要介紹了Tomcat服務(wù)器配置的方法教大家如何使用Tomcat服務(wù)器,感興趣的小伙伴們可以參考一下
    2016-04-04
  • Java抽象類和接口的區(qū)別詳情

    Java抽象類和接口的區(qū)別詳情

    這篇文章主要介紹的是Java抽象類和接口的區(qū)別詳情,
    2021-11-11
  • log4j的使用詳細(xì)解析

    log4j的使用詳細(xì)解析

    最近在整理公司產(chǎn)品的日志輸出規(guī)范,涉及l(fā)og4j的使用介紹,就簡(jiǎn)單整理了一下。需要的朋友可以過(guò)來(lái)參考參考
    2013-08-08
  • JAVA異常體系結(jié)構(gòu)詳解

    JAVA異常體系結(jié)構(gòu)詳解

    Java把異常當(dāng)作對(duì)象來(lái)處理,并定義一個(gè)基類java.lang.Throwable作為所有異常的超類,下面通過(guò)本文給大家分享JAVA異常體系結(jié)構(gòu),感興趣的朋友一起看看吧
    2017-11-11
  • Java利用trueLicense實(shí)現(xiàn)項(xiàng)目離線證書(shū)授權(quán)操作步驟

    Java利用trueLicense實(shí)現(xiàn)項(xiàng)目離線證書(shū)授權(quán)操作步驟

    文章介紹了如何使用trueLicense實(shí)現(xiàn)離線授權(quán)控制,包括生成公私鑰、創(chuàng)建證書(shū)校驗(yàn)?zāi)K、生成證書(shū)模塊和測(cè)試模塊,通過(guò)這種方式,可以控制用戶使用的項(xiàng)目模塊、授權(quán)周期、使用的設(shè)備和服務(wù)器,感興趣的朋友跟隨小編一起看看吧
    2024-11-11
  • java數(shù)據(jù)結(jié)構(gòu)基礎(chǔ):算法

    java數(shù)據(jù)結(jié)構(gòu)基礎(chǔ):算法

    這篇文章主要介紹了Java的數(shù)據(jù)解構(gòu)基礎(chǔ),希望對(duì)廣大的程序愛(ài)好者有所幫助,同時(shí)祝大家有一個(gè)好成績(jī),需要的朋友可以參考下,希望能給你帶來(lái)幫助
    2021-07-07
  • IDEA中關(guān)于enter鍵換行的問(wèn)題

    IDEA中關(guān)于enter鍵換行的問(wèn)題

    這篇文章主要介紹了IDEA中關(guān)于enter鍵換行的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • spring 自定義讓@Value被解析到

    spring 自定義讓@Value被解析到

    這篇文章主要介紹了spring 自定義讓@Value被解析到,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • Java使用POI從Excel讀取數(shù)據(jù)并存入數(shù)據(jù)庫(kù)(解決讀取到空行問(wèn)題)

    Java使用POI從Excel讀取數(shù)據(jù)并存入數(shù)據(jù)庫(kù)(解決讀取到空行問(wèn)題)

    有時(shí)候需要在java中讀取excel文件的內(nèi)容,專業(yè)的方式是使用java POI對(duì)excel進(jìn)行讀取,這篇文章主要給大家介紹了關(guān)于Java使用POI從Excel讀取數(shù)據(jù)并存入數(shù)據(jù)庫(kù),文中介紹的辦法可以解決讀取到空行問(wèn)題,需要的朋友可以參考下
    2023-12-12

最新評(píng)論

合山市| 璧山县| 阜南县| 汶川县| 许昌市| 怀仁县| 南丹县| 红桥区| 资讯 | 瑞昌市| 灵寿县| 文安县| 白水县| 玛沁县| 驻马店市| 林芝县| 扬中市| 台山市| 靖江市| 裕民县| 石城县| 嘉鱼县| 盱眙县| 资溪县| 桐乡市| 奉贤区| 玉屏| 阳曲县| 崇明县| 沂南县| 和静县| 神木县| 兰州市| 泰和县| 米林县| 教育| 昆山市| 望城县| 永兴县| 工布江达县| 清流县|