新しいVaadinプロジェクトで本当に奇妙な問題が発生しました。アプリケーションを起動してユーザーでログインし、ブラウザを切り替えてサイトを再度開くと、セッションが共有されているようです。私は両方のWindowsで同じコンテンツを持っています。
私はこの問題に関するいくつかのフォーラム投稿を読みました、彼らが言うすべては同じブラウザでアプリを開かないでください。OK、VMを起動しますが、同じ問題です。または、コンテキストからすべての静的変数を削除します。ThreadLocal-Patternを使用して、これを実行しました。
何が悪いのか全くわかりません。私が信じているのは、Spring ContextがVaadinを殺すということですが、VaadinとSpringでこのような経験をした人はいますか?
SpringとVaadinを一緒に使用するには、NicolasFrankelによるVaadin用のSpringIntgration Addon(https://vaadin.com/directory#addon/spring-integration)を使用します。
さらに調査するために、アプリケーションコードを投稿します。
===================
Vaadinアプリケーションクラス:
public class MainApplication extends Application implements HttpServletRequestListener {
private static final long serialVersionUID = 2067470624065324231L;
private static ThreadLocal<MainApplication> threadLocal = new ThreadLocal<MainApplication>();
private Window mainWindow;
//Viewmanager
private ViewManager viewManager;
private Professor professor;
//DAO Classes and Bean Setter´s
ProfessorDAO professorDAO;
QuestionDAO questionDAO;
AnswerDAO answerDAO;
AnsweredDAO answeredDAO;
QRCodeDAO qrCodeDAO;
public void setProfessorDAO(ProfessorDAO professorDAO) {
System.out.println("Setting ProfessorDAO!");
System.out.println(professorDAO.toString());
this.professorDAO = professorDAO;
}
public void setQuestionDAO(QuestionDAO questionDAO) {
System.out.println("Setting QuestionDAO!");
System.out.println(questionDAO.toString());
this.questionDAO = questionDAO;
}
public void setAnswerDAO(AnswerDAO answerDAO) {
System.out.println("Setting AnswerDAO!");
System.out.println(answerDAO.toString());
this.answerDAO = answerDAO;
}
public void setAnsweredDAO(AnsweredDAO answeredDAO) {
System.out.println("Setting AnsweredDAO!");
System.out.println(answeredDAO.toString());
this.answeredDAO = answeredDAO;
}
public void setQrCodeDAO(QRCodeDAO qrCodeDAO) {
System.out.println("Setting QRCodeDAO!");
System.out.println(qrCodeDAO.toString());
this.qrCodeDAO = qrCodeDAO;
}
public ProfessorDAO getProfessorDAO() {
return professorDAO;
}
public QuestionDAO getQuestionDAO() {
return questionDAO;
}
public AnswerDAO getAnswerDAO() {
return answerDAO;
}
public AnsweredDAO getAnsweredDAO() {
return answeredDAO;
}
public QRCodeDAO getQrCodeDAO() {
return qrCodeDAO;
}
//Currently logged in Professor.
public Professor getProfessor() {
return professor;
}
public void setProfessor(Professor professor) {
this.professor = professor;
}
public static void setInstance(MainApplication application){
threadLocal.set(application);
}
public ViewManager getViewManager() {
return viewManager;
}
public void setViewManager(ViewManager viewManager) {
this.viewManager = viewManager;
}
public static MainApplication getInstance(){
return threadLocal.get();
}
public MainApplication() {
}
@Override
public void init() {
setInstance(this);
setTheme("crs");
mainWindow = new Window("CRS -- Classroom Response System");
setMainWindow(mainWindow);
viewManager = new ViewManager(mainWindow);
viewManager.switchScreen(LoginScreen.class.getName(), new LoginScreen());
//mainWindow = new MainWindow("CRS -- Classroom Response System");
//setMainWindow(mainWindow);
}
public void onRequestStart(HttpServletRequest request,
HttpServletResponse response) {
MainApplication.setInstance(this);
}
public void onRequestEnd(HttpServletRequest request,
HttpServletResponse response) {
threadLocal.remove();
}
web.xml:
<display-name>CRSServer</display-name>
<context-param>
<description>
Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>CRS</servlet-name>
<servlet-class>ch.frankel.vaadin.spring.SpringApplicationServlet</servlet-class>
<init-param>
<description>
Vaadin application class to start</description>
<param-name>applicationBeanName</param-name>
<param-value>cs.hm.edu.kreipl.crs.frontend.MainApplication</param-value>
</init-param>
<init-param>
<description>
Application widgetset</description>
<param-name>widgetset</param-name>
<param-value>cs.hm.edu.kreipl.crs.widgetset.CrsserverWidgetset</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CRS</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring-config.xml</param-value>
</context-param>
春のコンテキスト
<context:component-scan base-package="cs.hm.edu.kreipl.crs" />
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/crs"></property>
<property name="username" value="crs"></property>
<property name="password" value="password"></property>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="annotatedClasses">
<list>
<value>cs.hm.edu.kreipl.crs.database.entity.Professor</value>
<value>cs.hm.edu.kreipl.crs.database.entity.Answer</value>
<value>cs.hm.edu.kreipl.crs.database.entity.Answered</value>
<value>cs.hm.edu.kreipl.crs.database.entity.Question</value>
<value>cs.hm.edu.kreipl.crs.database.entity.QuestionQRCode</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
<tx:annotation-driven/>
<!-- VAADIn Startup -->
<bean id="cs.hm.edu.kreipl.crs.frontend.MainApplication" class="cs.hm.edu.kreipl.crs.frontend.MainApplication">
<property name="answerDAO" ref="answerDAO" />
<property name="answeredDAO" ref="answeredDAO" />
<property name="professorDAO" ref="professorDAO" />
<property name="qrCodeDAO" ref="qrCodeDAO" />
<property name="questionDAO" ref="questionDAO" />
</bean>
<bean id="professorDAO" class="cs.hm.edu.kreipl.crs.database.implementation.ProfessorDAOImpl">
<constructor-arg>
<value>cs.hm.edu.kreipl.crs.database.entity.Professor</value>
</constructor-arg>
<property name="hibernateTemplate" ref="mySessionFactory"/>
</bean>
<bean id="questionDAO" class="cs.hm.edu.kreipl.crs.database.implementation.QuestionDAOImpl">
<constructor-arg>
<value>cs.hm.edu.kreipl.crs.database.entity.Question</value>
</constructor-arg>
<property name="hibernateTemplate" ref="mySessionFactory"/>
</bean>
<bean id="qrCodeDAO" class="cs.hm.edu.kreipl.crs.database.implementation.QRCodeDAOImpl">
<constructor-arg>
<value>cs.hm.edu.kreipl.crs.database.entity.QuestionQRCode</value>
</constructor-arg>
<property name="hibernateTemplate" ref="mySessionFactory"/>
</bean>
<bean id="answerDAO" class="cs.hm.edu.kreipl.crs.database.implementation.AnswerDAOImpl">
<constructor-arg>
<value>cs.hm.edu.kreipl.crs.database.entity.Answer</value>
</constructor-arg>
<property name="hibernateTemplate" ref="mySessionFactory"/>
</bean>
<bean id="answeredDAO" class="cs.hm.edu.kreipl.crs.database.implementation.AnsweredDAOImpl">
<constructor-arg>
<value>cs.hm.edu.kreipl.crs.database.entity.Answered</value>
</constructor-arg>
<property name="hibernateTemplate" ref="mySessionFactory"/>
</bean>
<bean id="deviceDAO" class="cs.hm.edu.kreipl.crs.database.implementation.DeviceDAOImpl">
<constructor-arg>
<value>cs.hm.edu.kreipl.crs.database.entity.Device</value>
</constructor-arg>
<property name="hibernateTemplate" ref="mySessionFactory"/>
</bean>
さらにクラスが必要な場合は、今すぐ教えてください。