使用Vaadin 14初始化VaadinServlet时出现NullPointerException

使用Vaadin 14初始化VaadinServlet时出现NullPointerException,vaadin,vaadin-flow,vaadin14,Vaadin,Vaadin Flow,Vaadin14,我正在将Vaadin 8应用程序升级为Vaadin 14。我必须手动定义VaadinServlet的扩展,而不是使用vaadin14的自动servlet注册,因为我需要将它映射到特定的URL模式。我正在使用web.xml来配置servlet,配置方式与为Vaadin 8成功配置servlet的方式相同 当我的servlet初始化时,我得到一个ServletException,它是由来自Vaadin代码的NullPointerException引起的。我查看了源代码,发现当Vaadin试图从ser

我正在将Vaadin 8应用程序升级为Vaadin 14。我必须手动定义
VaadinServlet
的扩展,而不是使用vaadin14的自动servlet注册,因为我需要将它映射到特定的URL模式。我正在使用
web.xml
来配置servlet,配置方式与为Vaadin 8成功配置servlet的方式相同

当我的servlet初始化时,我得到一个
ServletException
,它是由来自Vaadin代码的
NullPointerException
引起的。我查看了源代码,发现当Vaadin试图从servlet的
ServletContext
获取
Lookup
实例时,会出现异常,相反,它返回null。我发现
Lookup
实例应该被添加到
LookupServletContainerInitializer
中的上下文中,但在我的例子中似乎没有发生这种情况

有人知道是什么导致了这个问题吗?
NullPointerException
的堆栈跟踪如下所示

Caused by: java.lang.NullPointerException at com.vaadin.flow.server.DeploymentConfigurationFactory.getTokenFileFromClassloader(DeploymentConfigurationFactory.java:341) at com.vaadin.flow.server.DeploymentConfigurationFactory.getTokenFileContents(DeploymentConfigurationFactory.java:311) at com.vaadin.flow.server.DeploymentConfigurationFactory.readBuildInfo(DeploymentConfigurationFactory.java:181) at com.vaadin.flow.server.DeploymentConfigurationFactory.createInitParameters(DeploymentConfigurationFactory.java:174) at com.vaadin.flow.server.VaadinServlet.createDeploymentConfiguration(VaadinServlet.java:152) at com.vaadin.flow.server.VaadinServlet.createServletService(VaadinServlet.java:190) at com.vaadin.flow.server.VaadinServlet.init(VaadinServlet.java:77) at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:602) ... 28 more 原因:java.lang.NullPointerException 位于com.vaadin.flow.server.DeploymentConfigurationFactory.getTokenFileFromClassloader(DeploymentConfigurationFactory.java:341) 位于com.vaadin.flow.server.DeploymentConfigurationFactory.getTokenFileContents(DeploymentConfigurationFactory.java:311) 位于com.vaadin.flow.server.DeploymentConfigurationFactory.readBuildInfo(DeploymentConfigurationFactory.java:181) 位于com.vaadin.flow.server.DeploymentConfigurationFactory.createInitParameters(DeploymentConfigurationFactory.java:174) 位于com.vaadin.flow.server.VaadinServlet.createDeploymentConfiguration(VaadinServlet.java:152) 位于com.vaadin.flow.server.VaadinServlet.createServletService(VaadinServlet.java:190) 位于com.vaadin.flow.server.VaadinServlet.init(VaadinServlet.java:77) 位于org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:602)
... 28更多的
LookupServletContainerInitializer
是一个
javax.servlet.ServletContainerInitializer
,它应该在初始化期间由servlet容器自动运行

有两种典型情况会跳过这部分初始化:


  • web.xml
    配置为跳过某些步骤,例如,因为
    元数据完成
    设置为true或存在空的
    ,但这是在引入
    LookupServletContainerInitializer
    之前,所以您必须单独处理该步骤。

    感谢您的帮助。我遵循了您提供的示例,不再得到
    NullPointerException
    ,尽管现在我在
    /VAADIN/static/client
    中的一个资源中得到了404错误,我不确定它是否相关。您能否澄清我应该将哪些Vaadin类传递给
    DevModeInitializer
    ?我看到您将在
    MainView
    中使用的每个组件的类传递给了它。是否有必要将我在应用程序中使用的每种类型的组件的类传递给它?如果您是手动执行操作,然后,您需要查看
    DevModeInitializer
    @handleTypes
    注释,并为应用程序的类路径上实现或使用列出的任何接口或注释进行注释的所有相关内容传递类。然后对属于Vaadin的所有其他
    ServletContainerInitializer
    子类重复相同的操作。或者,将servlet容器配置为自动为您执行此操作
    /VAADIN/static/client
    可能与
    @PWA
    有关。