Java 如何在vaadin中动态推送更新页面?

Java 如何在vaadin中动态推送更新页面?,java,spring,vaadin,vaadin-push,Java,Spring,Vaadin,Vaadin Push,我有一个使用Vaadin和Spring+Security的工作应用程序。我现在尝试使用vaadinpush动态地将更新推送到客户端接口 我想创建一个对所有客户端都相同的视图。视图应该得到一个计数器,该计数器通过push动态递增。因此,当客户端显示页面时,计数器会自我更新,或者在我的示例中:向页面附加多个标签组件。每个客户端都应该看到相同的值 但是我没有看到网页上的更改。为什么? //the static controller the dynamically changes content @Co

我有一个使用Vaadin和Spring+Security的工作应用程序。我现在尝试使用vaadinpush动态地将更新推送到客户端接口

我想创建一个对所有客户端都相同的视图。视图应该得到一个计数器,该计数器通过push动态递增。因此,当客户端显示页面时,计数器会自我更新,或者在我的示例中:向页面附加多个标签组件。每个客户端都应该看到相同的值

但是我没有看到网页上的更改。为什么?

//the static controller the dynamically changes content
@Controller
public class ViewPresenter {
    private static int counter = 0;

    @Autowired
    private void StaticView view;

    @Scheduled(fixedRate = 1000)
    public void refresh() {
        //push the content change periodically to frontend
        view.getUI().access(new Runnable() {
            @Override
            public void run() {
                view.addComponent(new Label("refresh: " + counter++);
                Sysout("update executed: " + counter); //OK, is printed
            }
        });
    }
}

//the static test component that gets a new label added on every content change
@VaadinComponent
public class StaticView extends CssLayout {
        //this is the view that every client should see
}

//the secured admin view
@VaadinView(name = "/secured")
@Scope("ui")
@Secured("user")
public class SecuredView extends VerticalLayout implements View {
    @Autowired
    private StaticView staticView;

    @Override
    public void enter(ViewChangeEvent event) {
        addComponent(staticView);
    }
}

//enable push
@Configuration
@Push
public class AppConfig {
}

@VaadinUI
@PreserveOnRefresh
public class ApplicationUI extends UI {

} 
只有手动刷新网页,我才能在客户端看到更改。但内容本身不会自动更改

也许@Push必须放在UI类上?但在这种情况下,我会得到以下错误:

java.lang.IllegalStateException:无法将响应挂起超过 会话超时。增加web.xml中会话超时的值 在 org.atmosphere.cpr.atmosphereSourceImpl.suspendAtmosphereSourceImpl.java:314 在 org.atmosphere.cpr.atmosphereSourceImpl.suspendAtmosphereSourceImpl.java:292 在 com.vaadin.server.communication.PushHandler$2.runPushHandler.java:129 在 com.vaadin.server.communication.PushHandler.callWithUiPushHandler.java:242 在 com.vaadin.server.communication.PushHandler.access$200PushHandler.java:55 在 com.vaadin.server.communication.PushHandler$1.onRequestPushHandler.java:73

解决方案基于:

server.sessionTimeout=30,带有@Pushtransport=Transport.LONG\u轮询