gpt4 book ai didi

spring - 当 session 未锁定时无法从父级中删除

转载 作者:行者123 更新时间:2023-12-03 03:06:41 25 4
gpt4 key购买 nike

当我用 2 个 session 测试我的应用程序时,在一个浏览器中一切正常,而在另一个浏览器中却出现异常。

@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@PreserveOnRefresh
@SpringComponent
public class TestUI extends UI {

@Autowired
MainLayout content;

@Autowired
DetailView detailView;

@Override
protected void init(VaadinRequest request) {
VaadinSession.setCurrent(VaadinSession.getCurrent());
Navigator navigator = new Navigator(this, detailView);
navigator.addView("tests", TestView.class);
setContent(content);
}
}

enter image description here

java.lang.IllegalStateException: Cannot remove from parent when the session is not locked. Furthermore, there is another locked session, indicating that the component might be about to be moved from one session to another. at com.vaadin.ui.AbstractSingleComponentContainer.removeFromParent(AbstractSingleComponentContainer.java:175) at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:148) at com.vaadin.ui.UI.setContent(UI.java:1312)

最佳答案

将 Vaadin 组件定义为 Spring 托管 bean 时,必须始终为它们定义一个非单例范围。例如:

@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class MainLayout extends VerticalLayout {

这是因为 Vaadin 组件只能有一个父组件。其他可能的范围有 @UIScope@ViewScope

关于spring - 当 session 未锁定时无法从父级中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36625149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com