springsession 实现session 共享

 首先加入依赖
1
2 <dependency> 3 <groupId>org.springframework.session</groupId> 4 <artifactId>spring-session</artifactId> 5 </dependency> 6 <dependency> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-redis</artifactId> 9 </dependency>

其次:application.properties

#server server.port=9090 server.address=localhost #redis spring.redis.host=192.168.1.10 spring.redis.port=6379
插入代码:

@Configuration @EnableRedisHttpSession
public class RedisSessionConfig { @Bean public static ConfigureRedisAction configureRedisAction() { return ConfigureRedisAction.NO_OP; } }

否则会报错:
  error creating bean with name enablerediskeyspacenotificationsinitializer
在Linus中  输入命令  redis-cli config set notify-keyspace-events Egx 来开启开启:notify-keyspace-events Egx


具体内容请参考:http://www.cnblogs.com/mengmeng89012/p/5519698.html


 Redis从3.2开始加强安全管理,如果redis没有设置密码,那么redis客户端只能从本地进行访问,如果是从其他机器连接过来访问的,就会报错

我这边没有设置密码 , 所以须关闭保护模式



  最终结果:



原文地址:https://www.cnblogs.com/zhao-blog/p/6669337.html