Spring Boot Java Config 设置会话超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40974955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Boot Java Config Set Session Timeout
提问by Timo Ademeit
How can I configure my (embedded) Tomcat Session Timeout in a Spring Boot Application?
如何在 Spring Boot 应用程序中配置我的(嵌入式)Tomcat 会话超时?
public class SessionListener implements HttpSessionListener{
@Override
public void sessionCreated(HttpSessionEvent se) {
se.getSession().setMaxInactiveInterval(5*60);
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
}}
I have a SessionListener but I have no idea in which class I have to add this Listener to the Context.
我有一个 SessionListener 但我不知道我必须在哪个类中将此侦听器添加到上下文中。
回答by Daryl
server.session.timeout in the application.properties file is now deprecated. The correct setting is:
application.properties 文件中的 server.session.timeout 现在已弃用。正确的设置是:
server.servlet.session.timeout=60s
Also note that Tomcat will not allow you to set the timeout any less than 60 seconds. For details about that minimum setting see https://github.com/spring-projects/spring-boot/issues/7383.
另请注意,Tomcat 不允许您将超时设置为小于 60 秒。有关该最低设置的详细信息,请参阅https://github.com/spring-projects/spring-boot/issues/7383。
回答by LucasP
You should be able to set the server.session.timeout
in your application.properties file.
您应该能够server.session.timeout
在 application.properties 文件中设置 。
ref: http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html
参考:http: //docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html
回答by user1553728
- Spring Boot version 1.0:
server.session.timeout=1200
- Spring Boot version 2.0:
server.servlet.session.timeout=10m
NOTE: If a duration suffixis not specified, seconds will be used.
- Spring Boot 1.0 版:
server.session.timeout=1200
- Spring Boot 2.0 版:
server.servlet.session.timeout=10m
注意:如果未指定持续时间后缀,则将使用秒。