【发布时间】: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