首页 > 解决方案 > 使用首选项可配置 Vaadin 会话超时

问题描述

当 UI 空闲超过 3 分钟时,我正在使用 Vaadin 8 和附加插件来实现会话超时。这是附加插件

<dependency>
   <groupId>org.vaadin.anna</groupId>
   <artifactId>cleanupservlet</artifactId>
   <version>2.0.0</version>
</dependency>

VaadinUI.java

@Override
    protected void init(VaadinRequest vaadinRequest) {

        // timeout for 3 mins
        VaadinSession.getCurrent().getSession().setMaxInactiveInterval(180);

        Responsive.makeResponsive(this);
        setLocale(vaadinRequest.getLocale());

        showMainView();
    }

VaadinServlet.java

@WebServlet(urlPatterns = "/*", name = "VaadinServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = VaadinServlet.class, productionMode = false, heartbeatInterval = 180, closeIdleSessions = true)
        public static class VaadinServlet extends CleanupServlet {

            @Override
            protected int getCleanupPollingInterval() {
                // how long to wait between session timeout checks
                return 2000;
            }

            @Override
            protected boolean alwaysCheckUITimeOuts() {
                // if you want to ensure UI cleanup on every check
                // regardless of session timeout, default false
                return true;
            }
        }

我没有 web.xml 来配置 inactiveInterval。有没有办法按照用户在首选项对话框中给出的方式配置 inactiveInterval 和 heartbeatInterval?

或者有什么方法可以实现用户可配置的会话超时?

任何帮助表示赞赏。

TIA

标签: javavaadinsession-timeoutvaadin8

解决方案


推荐阅读