我不管理設置會話超時我Jhipster Web應用程序(春季啓動+彈簧安全+ angularJS)如何設置會話超時彈簧啓動tomcat的嵌入
我只是做了最簡單的方法:
...
/**
* Configuration of web application with Servlet 3.0 APIs.
*/
@Configuration
public class WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer
{
....
@Inject
private ServerProperties serverProperties;
....
/**
* Set up Mime types.
*/
@Override
public void customize(ConfigurableEmbeddedServletContainer container)
{
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
// IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
mappings.add("html", "text/html;charset=utf-8");
// CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
mappings.add("json", "text/html;charset=utf-8");
container.setSessionTimeout(serverProperties.getSession().getTimeout(), TimeUnit.MINUTES);
log.info("SessionTimeout = {}", serverProperties.getSession().getTimeout());
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/login"));
container.setMimeMappings(mappings);
}
...
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties
{
private Session session = new Session();
public static class Session
{
private int timeout = 6;
public int getTimeout()
{
return timeout;
}
public void setTimeout(int timeout)
{
this.timeout = timeout;
}
}
public Session getSession()
{
return session;
}
public void setSession(Session session)
{
this.session = session;
}
}
Application.yml
server:
port: 8080
session:
timeout: 1
日誌通知在1分鐘內長度的會話:
2016-07-28 16:17:03.103 INFO 6248 --- [ restartedMain] com.tess2i.config.WebConfigurer : SessionTimeout = 1
啓動WebApp後,我登錄了WebApp,然後等了1分多鐘。然後我點擊某處查詢服務器。所有人都還在工作。沒有會話錯誤/重定向。
還有什麼需要做的?
有沒有必要爲您的自定義實現 - 默認情況下使用'server.session.timeout'屬性。你確定你沒有使用JWT認證嗎?還是記得啓用? –
根據文檔,該屬性的單位是秒。 server.session.timeout =#以秒爲單位的會話超時。 http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html –