应用场景。比如我们使用 nginx 进行配置负载均衡的时候 ,那么多个服务器就需要共享session。那么就需要将session存到一个大家都可以访问的。这样才对嘛。
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
yml中去配置redis
spring:
redis:
host: localhost
port: 6379
password:
在启动类上面添加注解:@EnableRedisHttpSession
@RequestMapping("/test")
public @ResponseBody String sessionTest(HttpSession session){
session.setAttribute("user","张三");
return "test";
}
然后用session可视化工具查看就好了