Spring Boot设置cookie和session过期时间

JavaSpring Boot大约 801 字

Spring Boot配置redis-session

  • cookie过期时间,单位是秒
  • cookie.setMaxAge(0)
  • cookie.setMaxAge(-1)
  • cookie.setMaxAge(60*60)
@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;
    }
}  
阅读 1622 · 发布于 2019-04-15

————        END        ————

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

昵称:
随便看看换一批