Spring Boot 设置 Cookie 和 Session 过期时间
Spring Boot Session Cookie About 815 wordsSpring 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;
}
}
Views: 8,855 · Posted: 2019-04-15
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...