【问题标题】:Unexpected Vaadin Session Expired and parallel spring boot applications意外的 Vaadin 会话过期和并行的 spring boot 应用程序
【发布时间】:2020-06-01 14:41:06
【问题描述】:

我正在使用 Vaadin 8.9.4 和 Spring boot 2.2.4.RELEASE。我有 2 个 Spring Boot 应用程序,FirstApplication (server.port=8083) 和 SecondApplication (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);
    }
}

【问题讨论】:

    标签: spring spring-boot vaadin vaadin8


    【解决方案1】:

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

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

    【讨论】:

      最近更新 更多