意外的 Vaadin 会话过期和并行 Spring Boot 应用程序

2023-12-08

我正在使用 Vaadin 8.9.4 和 Spring boot 2.2.4.RELEASE。我有 2 个 Spring Boot 应用程序,FirstApplication (server.port=8083) 和第二个应用程序 (server.port=8084)。两个应用程序都有@SpringUI带注释的类扩展了 UI 类,如下所示。一旦我单击 SecondApplication 中的按钮,FirstApplication 的会话就会过期,反之亦然。仅当我并行使用两个 Chorme 选项卡时才会发生这种情况。如果我使用两个不同的浏览器,一切都会按预期工作。

这是否是某种错误,因为我期望两个应用程序的会话之间没有关系,仅仅是因为它们在不同的端口上独立运行。

注意:我是 Spring Boot 的新手,我正在尝试构建 2 个通过 Rest API 相互通信的微服务。

@SpringUI
@Theme("valo")
public class FirstApplicationUI extends UI {

    private static final long serialVersionUID = 9197592298697220144L;

    @Override
    protected void init(final VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        final Label label = new Label("First Application");
        final Button button = new Button("click");

        button.addClickListener(e -> Notification.show("First Application"));

        layout.addComponents(label, button);

        setContent(layout);
    }
}

@SpringUI
@Theme("valo")
public class SecondApplicationUI extends UI {

    private static final long serialVersionUID = 9059755286859361908L;

    @Override
    protected void init(final VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        final Label label = new Label("Second Application");
        final Button button = new Button("click");

        button.addClickListener(e -> Notification.show("Second Application"));

        layout.addComponents(label, button);

        setContent(layout);
    }
}

这是两个应用程序争夺同一个 cookie;两者都使用相同的名称,并且您的浏览器很乐意向两个后端发送相同的 cookie,因为不考虑端口。

更改至少一份申请中的姓名;看server.servlet.session.cookie.name in https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

意外的 Vaadin 会话过期和并行 Spring Boot 应用程序 的相关文章

随机推荐