首先列出正確的配置 ,最後是錯誤的原因

環境

     spring boot 2.0.5.RELEASE

 依賴

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
</dependency>

程式碼配置

@EnableRedisHttpSession(maxInactiveIntervalInSeconds= 7200)
public class SessionConfig {
}

application.yml 配置

web1

server:
  port: 8082
  servlet:
    context-path: /dims-rbac-web
    session:
      cookie:
        path: /
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  application:
    name: dims-rbac-web
  redis:
    host: localhost
    port: 6379
  session:
    store-type: redis
    redis:
      flush-mode: on_save
      namespace: spring:session
dubbo:
  application:
    name: dims-rbac-web
  protocol:
    name: dubbo
    port: 20880
  registry:
    address: zookeeper://localhost:2881
    timeout: 1000

web2

server:
  port: 8083
  servlet:
    context-path: /dims-crm-web
    session:
      cookie:
        path: /
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  application:
    name: dims-crm-web
  redis:
    host: localhost
    port: 6379
  session:
    store-type: redis
    redis:
      flush-mode: on_save
      namespace: spring:session
dubbo:
  application:
    name: dims-crm-web
  protocol:
    name: dubbo
    port: 20880
  registry:
    address: zookeeper://localhost:2881
    timeout: 1000

 啟動類註解 web1

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

啟動類註解web2

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

上面是正確的配置,

但是 如果在配置了 context-path 不是預設的/ 的情況下  cookie的path預設和context-path一致,就會導致cookie的作用域不一致導致無法共享,此時就必須加上 cookie的path為/