意外的Vaadin会话已过期,并行spring引导应用程序
我使用的是Vaadin 8.9.4和Spring boot 2.2.4。释放我有两个spring启动应用程序,第一个应用程序(server.port=8083
)和第二个应用程序(server.port=8084
)。这两个应用程序都有@SpringUI
注释类扩展UI类,如下所示。单击第二个应用程序中的按钮后,第一个应用程序的会话将立即过期,反之亦然。只有当我并行使用两个弦选项卡时,才会发生这种情况。如果我使用两种不同的浏览器,一切正常
这是一种bug吗?我认为这两个应用程序的会话之间没有关系,因为它们在不同的端口上独立运行
注意:我是spring boot的新手,我正在尝试构建2个通过RESTAPI相互通信的micorService
@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);
}
}
# 1 楼答案
这是您的两个应用程序为同一个cookie而斗争;两者都使用相同的名称,并且您的浏览器愉快地向两个后端发送相同的cookie,因为不考虑端口
更改至少一个应用程序中的名称;见https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html中的
server.servlet.session.cookie.name