意外的 Vaadin 会话已过期和并行 spring 引导应用程序

Unexpected Vaadin Session Expired and parallel spring boot applications

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

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

注意:我是 spring 引导的新手,我正在尝试构建 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,因为不考虑端口。

至少在您的一个应用程序中更改名称;在 https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

中查看 server.servlet.session.cookie.name