Vaadin Flow&Spring Boot:在多个标签/窗口中打开时出错

时间:2018-09-20 08:49:17

标签: spring session mvp vaadin10 vaadin-flow

我目前正在使用MVP模式使用Vaadin Flow(v11.0.0)和Spring Boot(v2.0.4)开发应用程序。只要仅在单个选项卡中打开该应用程序即可正常运行。重新加载时会刷新整个页面,这完全可以。同时在第二个标签页或窗口中打开它(无论是否隐身都没关系)可以正常工作。但是,当我在一个窗口中单击某个内容,然后在另一个窗口中单击时,会发生以下错误:

java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:515) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:529) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.StateTree.checkHasLock(StateTree.java:390) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.StateTree.markAsDirty(StateTree.java:258) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.StateNode.markAsDirty(StateNode.java:326) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.nodefeature.NodeValue.markAsDirty(NodeValue.java:85) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.nodefeature.NodeValue.setValue(NodeValue.java:78) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.nodefeature.TextNodeMap.setText(TextNodeMap.java:52) ~[flow-server-1.0.5.jar:na]

我只有一个视图(因此也是演示者),我会这样注释:

@Route(value = LogAnalysis.route)
@PageTitle(LogAnalysis.name)
class LogAnalysisView(val presenter: LogAnalysis.ViewPresenter) : VerticalLayout(), LogAnalysis.View, BeforeEnterObserver { ... }

@Component
@UIScope
@VaadinSessionScope
class LogAnalysisPresenter(val service: LogAnalysis.Service) : LogAnalysis.ServicePresenter, LogAnalysis.ViewPresenter { ... }

1 个答案:

答案 0 :(得分:0)

我也通过在服务(模型)中添加@UIScope注释来解决了这个问题。

我认为该服务可以是单例的,因为它只是从数据库中获取和准备数据,但是该服务拥有对演示者的引用,该引用在每次创建新Session时都会被覆盖。