我正在使用 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 的 session 就会过期,反之亦然。仅当我并行使用两个 Chorme 选项卡时才会发生这种情况。如果我使用两个不同的浏览器,一切都会按预期工作。
这是否是某种错误,因为我预计两个应用程序的 session 之间没有关系,只是因为它们在不同的端口上独立运行。
注意:我是 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,因为不考虑端口。
更改至少一个应用程序中的名称;请参阅 https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html 中的 server.servlet.session.cookie.name
关于spring - 意外的 Vaadin session 过期和并行 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60266286/