我的英语存在一些问题,所以我对错误表示歉意。在tomcat上的Vaadin web应用程序只为所有用户创建一个web应用程序的实例
我是Java编程的初学者。我使用IntelliJIdea作为IDE,Vaadin框架创建GUI和tomcat作为Web服务器。项目是使用maven生成的。 要创建我用下面的来源为例应用:
有应用类,(这不是com.vaadin.Application
继承者),但单。
package com.exadel.dinnerorders.vaadinwindow.application;
import com.exadel.dinnerorders.entity.Order;
import com.exadel.dinnerorders.entity.User;
import com.exadel.dinnerorders.service.TasksManagerService;
import com.google.common.eventbus.EventBus;
public class Application {
private EventBus eventBus = new EventBus();
private static Application INSTANCE = new Application();
private User user;
private Order order;
private TasksManagerService tasksManagerService = new TasksManagerService();
private Application() {
tasksManagerService.start();
}
public synchronized static Application getInstance(){
return INSTANCE;
}
public EventBus getEventBus() {
return eventBus;
}
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public TasksManagerService getTasksManagerService() {
return tasksManagerService;
}
}
而且有WebApplicationController
类,它扩展com.vaadin.Application
。
package com.exadel.dinnerorders.vaadinwindow.application;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.*;
import java.util.Collection;
public class WebApplicationController extends com.vaadin.Application {
private EventBus eventBus = Application.getInstance().getEventBus();
private Layout loginLayout;
private String datePattern = "YYYY-MM-DD";
@Override
public void init() {
createLayouts();
createMainWindow();
eventBus.register(this);
setTheme("apptheme");
}
//some another methods for initialization main window and layouts
}
所以,看来我的应用程序工作正常。但是我面临下一个问题: 我在Tomcat 7配置中运行应用程序。它启动没有任何问题。我将Opera作为浏览器打开并以user1身份登录。一切似乎都正确。然后,我打开Google Chrome或其他浏览器并以user2登录。如果在Opera中刷新窗口,它将显示知道user2登录,但不是user1。我试图在不同的计算机上做同样的事情,并得到了同样的结果。 (在一台机器上记录为user1,在另一台上记录为user2)。 Firebug显示sessionsID在不同的浏览器中不同。
看来,这个问题是在web.xml文件中,在那里我配置的servlet。但我曾尝试过不同的配置示例,并始终得到相同的结果。
不幸的是,我没有设法在谷歌或其他论坛找到答案。
谢谢。我已经替换了单例应用程序,并且Web应用程序开始以正确的方式工作。 – Sergey