spring: session: # 设置session保存类型,这里保存在redis中 store-type: redisserver: # session默认的过期时间 servlet: session: timeout: 30m
3.配置redis(略) 4.在主启动类上添加一个注解(关于这个注解的说明如下)@EnableRedisHttpSession //开启redis作为session的存储
The @EnableRedisHttpSession annotation creates a Spring Bean with the name of springSessionRepositoryFilter that implements Filter、The filter is in charge of replacing the HttpSession implementation to be backed by Spring Session、In this instance, Spring Session is backed by Redis.
5.向redis中存储的session,data对象的类一定要实现序列化接口session.setAttribute("user",data);
6.默认发放的令牌,session=aaaaa,作用域:当前域(需要扩大到父域名作用范围)另外需要使用json的序列化方式来序列化对象数据到redis中
@Configurationpublic class GulimallSessionConfig { @Bean public cookieSerializer getcookieSerializer(){ DefaultcookieSerializer cookieSerializer = new DefaultcookieSerializer(); //指定cookie的作用域和cookie的名字 cookieSerializer.setDomainName("父域名"); cookieSerializer.setcookieName("session名字"); //将对象放入容器中 return cookieSerializer; } @Bean public RedisSerializer