Vaadin Flow & Spring 引导:在多个 tabs/windows 中打开时出错

Vaadin Flow & Spring Boot: Error when opened in multiple tabs/windows

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

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 { ... }

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

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