diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java index 530d12e..1eaec87 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionConfig.java @@ -17,10 +17,8 @@ import org.springframework.session.web.http.DefaultCookieSerializer; * @Date 2020/7/29 9:46 上午 * @Version 1.0 **/ - @Configuration -// 设置session的过期时间为一天 -@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 24 * 60 * 60 * 10) +@EnableRedisHttpSession public class RedisSessionConfig { @Bean @@ -30,9 +28,11 @@ public class RedisSessionConfig { // 创建 DefaultCookieSerializer 对象 DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); - sessionIdResolver.setCookieSerializer(cookieSerializer); // 设置到 sessionIdResolver 中 + sessionIdResolver.setCookieSerializer(cookieSerializer); + // 设置到 sessionIdResolver 中 cookieSerializer.setCookieName(BizConst.COOKIE_KEY); cookieSerializer.setCookieMaxAge(SessionTimeConstant.SESSION_TIME_SECONDS); return sessionIdResolver; } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionTimeoutConfig.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionTimeoutConfig.java new file mode 100644 index 0000000..99676cf --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/config/RedisSessionTimeoutConfig.java @@ -0,0 +1,38 @@ +package com.ningdatech.pmapi.user.security.auth.config; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Configuration; +import org.springframework.session.data.redis.RedisIndexedSessionRepository; +import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration; + +import javax.annotation.PostConstruct; + +/** + *
+ * 设置session的过期时间为一天 + *
+ * + * @Author LiuXinXin + * @Date 2020/7/29 9:46 上午 + * @Version 1.0 + **/ +@Configuration +@RequiredArgsConstructor +@AutoConfigureAfter(RedisHttpSessionConfiguration.class) +public class RedisSessionTimeoutConfig { + + @Value("${spring.session.timeout:60 * 60 * 4}") + private Integer springSessionTimeout; + + private final RedisHttpSessionConfiguration redisHttpSessionConfiguration; + private final RedisIndexedSessionRepository redisIndexedSessionRepository; + + @PostConstruct + public void sessionTimeoutTime() { + redisHttpSessionConfiguration.setMaxInactiveIntervalInSeconds(springSessionTimeout); + redisIndexedSessionRepository.setDefaultMaxInactiveInterval(springSessionTimeout); + } + +} diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index e95eb4f..6820c94 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -11,6 +11,7 @@ spring: store-type: redis redis: namespace: "spring:session" + timeout: 864000 redis: timeout: 5000 host: 47.98.125.47