我们目前正在基于Vaadin Flow入门包开发一个新的Vaadin Web应用程序。它与码头服务器一起运行,该码头服务器通过maven调用启动。最近,经常弹出一个错误,阻止我访问浏览器中的应用程序,从而导致异常堆栈跟踪(在浏览器和后端)com.vaadin.flow.server.VaadinSession cannot be cast to com.vaadin.flow.server.VaadinSession
。这是完整的堆栈跟踪。
javax.servlet.ServletException: javax.servlet.ServletException: com.vaadin.flow.server.ServiceException: java.lang.ClassCastException: com.vaadin.flow.server.VaadinSession cannot be cast to com.vaadin.flow.server.VaadinSession
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:531)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.servlet.ServletException: com.vaadin.flow.server.ServiceException: java.lang.ClassCastException: com.vaadin.flow.server.VaadinSession cannot be cast to com.vaadin.flow.server.VaadinSession
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:302)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:857)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
... 15 more
Caused by: com.vaadin.flow.server.ServiceException: java.lang.ClassCastException: com.vaadin.flow.server.VaadinSession cannot be cast to com.vaadin.flow.server.VaadinSession
at com.vaadin.flow.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1535)
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1498)
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:300)
... 33 more
Caused by: java.lang.ClassCastException: com.vaadin.flow.server.VaadinSession cannot be cast to com.vaadin.flow.server.VaadinSession
at com.vaadin.flow.server.VaadinService.readFromHttpSession(VaadinService.java:2071)
at com.vaadin.flow.server.VaadinService.loadSession(VaadinService.java:2051)
at com.vaadin.flow.server.VaadinService.getExistingSession(VaadinService.java:942)
at com.vaadin.flow.server.VaadinService.doFindOrCreateVaadinSession(VaadinService.java:791)
at com.vaadin.flow.server.VaadinService.findOrCreateVaadinSession(VaadinService.java:766)
at com.vaadin.flow.server.VaadinService.findVaadinSession(VaadinService.java:624)
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1480)
... 34 more
现在stacktrace本身就是其中一种,我之前从未见过类似的东西,因为它说它无法将VaadinSession强制转换为VaadinSession,这是不幸的。我很确定这些东西是由Vaadin本身处理的,我只是将其用作黑匣子,所以现在我真的不知道这些错误来自何处以及如何解决。
我正在扩展VaadinServlet以便连接到servlet和会话初始化,但是代码非常简单(尽管我不得不说我不是会话初始化方面的高手,所以我只是将其从其他教程中删除了) 。我不确定这是否与它有关,反正就是下面的代码。
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(this);
getService().addSessionDestroyListener(this);
logger.info("servlet initialized");
}
@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
// Do session start stuff here
logger.info("session initialized");
SessionBean sessionBean = new SessionBean();
sessionBean.setPlant(Config.getInstance().getPlant());
// TODO Berechtigungen aus dem Nutzer auslesen
sessionBean.setAuthorizations(AUTHS);
event.getSession().setAttribute(SessionBean.class, sessionBean);
event.getSession().setAttribute(BPService.class, new BPService());
}
@Override
public void sessionDestroy(SessionDestroyEvent event) {
event.getSession().setAttribute(SessionBean.class, null);
event.getSession().setAttribute(BPService.class, null);
}
该错误在热部署以及全新启动时发生。重新启动应用程序服务器不一定能解决问题。一旦页面调用中出现错误(与哪个浏览器无关,我在Chrome,Opera,Firefox和IE中都出现了这些错误),如果我刷新此特定页面或尝试通过同一浏览器的新窗口。如果我切换到隐身窗口或切换浏览器,它将不会在新窗口中出现,但仍会在旧窗口中弹出。
mvn jetty:run
,码头有9.4.11.v20180605 我认为我目前正在使用Vaadin Flow的全部内容,我不确定它如何处理依赖关系,但这是我目前对Vaadin的唯一依赖:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
我尝试将码头服务器切换到其他版本,但没有成功。将Vaadin从11更新为12对该错误也没有影响。