NPE SpringLookupInitializer createLookup Spring-Vaadin 19+

问题描述

在尝试更新到最新版本的 Vaadin(问题时为 20)时,由于 SpringLookupInitializer 中的 NPE,我的应用程序将无法启动。当我使用 Vaadin 19 时,这是第一次开始使用 SpringLookupInitializer 并且我第一次开始遇到错误,我必须始终使用 Spring-Vaadin 12.4.0 才能启动应用程序。错误似乎来自此更改...

在 12.4.0 中,SpringLookupInitializer 中的代码定义为:

    @Override
    protected Lookup createLookup(VaadinContext context,Map<Class<?>,Collection<Class<?>>> services) {
        WebApplicationContext appContext = getApplicationContext(context);
        return new SpringLookup(appContext,(spi,impl) -> instantiate(appContext,spi,impl),services);
    }

    private WebApplicationContext getApplicationContext(VaadinContext context) {
        VaadinServletContext servletContext = (VaadinServletContext) context;
        WebApplicationContext appContext = WebApplicationContextUtils
                .getWebApplicationContext(servletContext.getContext());
        if (appContext == null) {
            // Spring behavior is always unbelievably surprising: under some
            // circumstances {@code appContext} may be null even though the app
            // context has been set via ApplicationContextAware: no idea WHY
            ApplicationContextwrapper wrapper = context
                    .getAttribute(ApplicationContextwrapper.class);
            appContext = wrapper == null ? null : wrapper.appContext;
        }
        return appContext;
    }

它以这种方式工作,因为它在继续之前进行检查和更正(基本上是评论所说的)。在最新版本中,删除了 getApplicationContext 并且不再执行检查

    @Override
    protected Lookup createLookup(VaadinContext context,Collection<Class<?>>> services) {
        WebApplicationContext appContext = WebApplicationContextUtils
                .getWebApplicationContext(
                        ((VaadinServletContext) context).getContext());
        return new SpringLookup(appContext,services);
    }

我不只使用 MVC 的 spring boot,并且在旧的 spring-vaadin 版本上一切正常。是否有理由不再执行此检查或已实施的其他措施可以阻止这种情况发生?

谢谢

解决方法

感谢您的报告 - 最新版本的 Vaadin Spring 附加组件似乎忽略了这些更改(在 PR #740 中)。我们正在完成更改并确保这些更改被向前移植,并且很快也会为 Vaadin 20 发布。

对于类似的情况,当更新 Vaadin 版本有问题时,建议直接将新问题打开到相应的存储库(如 vaadin/springvaadin/flow),以便被立即注意到开发团队。谢谢

编辑:此修复程序已在 Vaadin Spring add-on version 17.0.1 中发布。您可以指定您的项目以明确使用该版本的 vaadin-spring 工件。它将包含在最迟于 6 月 14 日下周一发布的 Vaadin 20.0.2 版本中。