• (9)springboot+redis实现session共享-copy


    1.场景描述

    因项目访问压力有点大,需要做负载均衡,但是登录使用的是公司统一提供的单点登录系统,需要做session共享,否则假如在A机器登录成功,在B机器上操作就会存在用户未登录情况。

    2. 解决方案

    因项目是springboot项目,采用Springboot+Springsession+Redis来实现session共享。

    2.1 pom.xml文件

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-redis</artifactId>
         <version>1.4.7.RELEASE</version>
     </dependency>
     <dependency>
         <groupId>org.springframework.session</groupId>
         <artifactId>spring-session-data-redis</artifactId>
     </dependency> 
    

    2.2 springboot中开启session支持

    springboot启动类添加@EnableRedisHttpSession标签来开启spring session支持,代码:

    @EnableRedisHttpSession
    @SpringBootApplication
    public class SptestApplication {
        public static void main(String[] args) {
        
            SpringApplication.run(SptestApplication.class, args);
        }
    }
    

    2.3 配置文件中增加配置项

    在application.properties中增加配置项

    spring.redis.host=10.192.168.13
    spring.redis.port=6379
    

    其他还有几个配置项,不影响使用,不详说了,需要了解的可以查看API。

  • 相关阅读:
    SAP Easy tree
    SAP Column tree
    SAP Tree
    SAP 文本框多行输入
    SAP -SE30 程序运行时间分析
    SAP 实例- 页签tabsrip
    ABAP CDS
    ABAP CDS
    ABAP CDS
    ABAP CDS
  • 原文地址:https://www.cnblogs.com/hanease/p/14520566.html
Copyright © 2020-2023  润新知