Springboot +复述,怎么实现会话共享

  介绍

小编给大家分享一下Springboot +复述,怎么实现会话共享,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!

<强>问题产生的原因?

<强>,  Springboot +复述,怎么实现会话共享

当多个应用做集群的时候,如何实现应用之间会话共享。

解决办法:

用一个容器保存会话,就能共享了。容器可以是数据库,缓存,文件等。当然这里性能最高的还是,

复述了。

实例代码:

1,环境jdk1.7 + springboot1.47 +复述3.2.0

pom文件:

<>之前,,,& lt; parent>   ,,,,,,,& lt; groupId> org.springframework.boot   ,,,,,,,& lt; artifactId> spring-boot-starter-parent   ,,,,,,,& lt; version> 1.4.7.RELEASE   ,,,,,,,& lt; relativePath/祝辞,& lt; !——, lookup  parent 得到repository ——比;   ,,,& lt;/parent>   ,,& lt; properties>   ,,,,,,,& lt; project.build.sourceEncoding> UTF-8   ,,,,,,,& lt; project.reporting.outputEncoding> UTF-8   ,,,,,,,& lt; java.version> 1.7 & lt;/java.version>   ,,,& lt;/properties>   ,,,,   & lt;才能dependencies>   ,,   ,,& lt; !——, spring  boot  web ——比;   ,,,,,,,& lt; dependency>   ,,,,,,,,,,,& lt; groupId> org.springframework.boot   ,,,,,,,,,,,& lt; artifactId> spring-boot-starter-web   ,,,,,,,& lt;/dependency>      ,,,,,,,& lt; dependency>   ,,,,,,,,,,,& lt; groupId> org.springframework.boot   ,,,,,,,,,,,& lt; artifactId> spring-boot-starter-test   ,,,,,,,,,,,& lt; scope> test   ,,,,,,,& lt;/dependency>   ,,,,,,,   ,,& lt; dependency>,,   ,,,,,,,& lt; groupId> org.springframework.boot,,   ,,,,,,,& lt; artifactId> spring-boot-starter-redis,,   & lt;/dependency>,,      & lt; dependency>,,   ,,,,,,,& lt; groupId> org.springframework.session,,   ,,,,,,,& lt; artifactId> spring-session-data-redis,,   & lt;/dependency>      & lt;才能/dependencies>

yml文件:

 #端口设置
  服务器:
  ,,端口:9999
  # mybatis连接设置
  春天:
  #复述才能配置
  复述才能:
  ,,,主持人:127.0.0.1
  ,,,#密码:123456
  ,,,端口:6379
  ,,,池:
  ,,,,,最大空闲:100
  ,,,,,min-idle: 1
  ,,,,,max-active: 1000
  ,,,,,最大等待:,1 

java代码:

 import  java.util.HashMap;
  import  java.util.Map;
  
  import  javax.servlet.http.HttpServletRequest;
  
  import  org.springframework.web.bind.annotation.RequestMapping;
  import  org.springframework.web.bind.annotation.ResponseBody;
  import  org.springframework.web.bind.annotation.RestController;
  
  @RestController
  @RequestMapping(“测试/?
  public  class  LoginController  {
  @RequestMapping (“test01")
  @ResponseBody
  public  Map<字符串,String>,登录(HttpServletRequest 点播){
  字符串,Map, map =, new  HashMap<字符串,,String> ();
  System.out.println(“进入项目00111111111111111111111 controler");
  map.put (“sessionId", req.getSession () .getId ());
  return 地图;
  }
  null

Springboot +复述,怎么实现会话共享