首先列出正确的配置 ,最后是错误的原因
环境
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为/