|
|
@@ -2,12 +2,17 @@ package com.ningdatech.pmapi.user.security.auth.config;//package com.ningdatech. |
|
|
|
|
|
|
|
import com.ningdatech.pmapi.common.constant.BizConst; |
|
|
|
import com.ningdatech.pmapi.user.security.auth.constants.SessionTimeConstant; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; |
|
|
|
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration; |
|
|
|
import org.springframework.session.web.http.CookieHttpSessionIdResolver; |
|
|
|
import org.springframework.session.web.http.DefaultCookieSerializer; |
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* 设置session的过期时间为一天 |
|
|
@@ -17,10 +22,9 @@ import org.springframework.session.web.http.DefaultCookieSerializer; |
|
|
|
* @Date 2020/7/29 9:46 上午 |
|
|
|
* @Version 1.0 |
|
|
|
**/ |
|
|
|
|
|
|
|
@Configuration |
|
|
|
// 设置session的过期时间为一天 |
|
|
|
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 24 * 60 * 60 * 10) |
|
|
|
@RequiredArgsConstructor |
|
|
|
@AutoConfigureAfter(RedisHttpSessionConfiguration.class) |
|
|
|
public class RedisSessionConfig { |
|
|
|
|
|
|
|
@Bean |
|
|
@@ -30,9 +34,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; |
|
|
|
} |
|
|
|
|
|
|
|
} |