Spring Boot设置cookie和session过期时间

Java Spring Boot 大约 801 字

Spring Boot配置redis-session

  • cookie过期时间,单位是秒
  • cookie.setMaxAge(0);//不记录cookie
  • cookie.setMaxAge(-1);//会话级cookie,关闭浏览器失效
  • cookie.setMaxAge(60*60);//过期时间为1小时
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 2592000, redisNamespace = "Test-Session")
public class RedisSessionConfig {

    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
        defaultCookieSerializer.setCookieMaxAge(2592000);
        //cookie名字 默认是 "SESSION"
        defaultCookieSerializer.setCookieName("sessionId");
        //域 默认是域名
        defaultCookieSerializer.setDomainName("xxx.com");
        //存储路径 默认是 "/"
        defaultCookieSerializer.setCookiePath("/");
        return defaultCookieSerializer;
    }
}  
阅读 3552 · 发布于 2019-04-15

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批