我创建了一个SpringBoot MVC / Security应用程序1.2.2.RELEASE,我的application.properties包含服务器设置,如
#Tomcat port and contextPath details
server.port=8080
server.contextPath=/test
#server.session-timeout=120
server.sessionTimeout=120
该 文件 状态
server.session-timeout= # session timeout in seconds
但是 ServerProperties.java 使用sessionTimeout;
如果你查看我提出的application.properties代码,我已经独立尝试了两个,但是我没有在2分钟后超时,我没有明确编写任何其他代码来执行任何会话handeling。
有人遇到过这个问题吗?我错过了什么或做错了什么?
我不知道由于某种原因只设置
server.session.timeout=120
然而,当我设置会话超时和cookie最大年龄时,对我来说不起作用如下:
server.session.cookie.max-age=120
server.session.timeout=120
它完美地运作
我不确定这个server.session.timeout是什么,因为当我将它设置为特定的数字并监视会话创建时,会话到期不会改变。
我正在使用spring会话和redis集成,在我的情况下,我需要将maxInactiveIntervalInSeconds设置为120(秒),这可以通过redisHttpSessionConfiguration来完成。
然后,如果我去redis寻找会话,我可以看到它的到期时间改为120秒,会话超时工作。
我的一个建议是尝试找出是否可以通过编程方式或在属性文件中配置会话的maxInactiveIntervalInSeconds(或类似)并监视会话更改。
(这适用于撰写本文时的Spring 1.5.x)
请注意,如果您正在使用 Redis会话@EnableRedisHttpSession (例如在其他评论中 @Phoebe Li的案子),然后将不应用应用程序属性server.session。您必须通过以下代码手动设置它:
@EnableRedisHttpSession
public class HttpSessionConfig {
@Bean
public RedisOperationsSessionRepository sessionRepository(RedisConnectionFactory factory) {
RedisOperationsSessionRepository sessionRepository = new RedisOperationsSessionRepository(factory);
//Set the TTL of redis' key, which in turn will expire session when TTL is reached
sessionRepository.setDefaultMaxInactiveInterval(15); //e.g. 15 seconds
return sessionRepository;
}I
}