【问题标题】:NPE SpringLookupInitializer createLookup Spring-Vaadin 19+NPE SpringLookupInitializer createLookup Spring-Vaadin 19+
【发布时间】:2021-06-02 18:31:35
【问题描述】:

在尝试更新到最新版本的 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,
            Map<Class<?>, Collection<Class<?>>> services) {
        WebApplicationContext appContext = WebApplicationContextUtils
                .getWebApplicationContext(
                        ((VaadinServletContext) context).getContext());
        return new SpringLookup(appContext,
                (spi, impl) -> instantiate(appContext, spi, impl), services);
    }

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

谢谢

【问题讨论】:

    标签: spring vaadin vaadin-flow


    【解决方案1】:

    感谢您的报告 - 最新版本的 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 版本中。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    相关资源
    最近更新 更多