Spring Boot Java Config Set Session Timeout

2019-01-18 12:07发布

How can I configure my (embedded) Tomcat Session Timeout in a Spring Boot Application?

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.

4条回答
放荡不羁爱自由
2楼-- · 2019-01-18 12:29

server.session.timeout in the application.properties file is now deprecated. The correct setting is:

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.

查看更多
来,给爷笑一个
3楼-- · 2019-01-18 12:30

You should be able to set the server.session.timeout in your application.properties file.

ref: http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

查看更多
何必那么认真
4楼-- · 2019-01-18 12:34

spring boot 1.0 server.session.timeout=1200
spring boot 2.0 server.servlet.session.timeout=10m

查看更多
太酷不给撩
5楼-- · 2019-01-18 12:48

i think it's good idea to set 1s for springboot

查看更多
登录 后发表回答