Vaadin 24.4.0.beta1空指针异常及Maven构建兼容问题求助
Vaadin开发异常解决方案
问题描述
- 基于IntelliJ IDEA + Java 17 + Vaadin 24.4.0.beta1开发从start.vaadin.com下载的多频道聊天Flow项目,添加
// todo注释后重启应用频繁触发空指针异常:
ERROR 48164 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [com.vaadin.flow.server.ServiceException: java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.RequestHandler.handleRequest(com.vaadin.flow.server.VaadinSession, com.vaadin.flow.server.VaadinRequest, com.vaadin.flow.server.VaadinResponse)" because "handler" is null] with root cause java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.RequestHandler.handleRequest(com.vaadin.flow.server.VaadinSession, com.vaadin.flow.server.VaadinRequest, com.vaadin.flow.server.VaadinResponse)" because "handler" is null at com.vaadin.flow.server.communication.SessionRequestHandler.handleRequest(SessionRequestHandler.java:64) ~[flow-server-24.4.0.beta1.jar:24.4.0.beta1] ...(省略后续栈帧)
- 清理生成文件并更换Vaadin版本后,执行
./mvnw持续出现Java版本兼容异常:
[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:24.3.11:prepare-frontend (default) on project chat-app: Execution default of goal com.vaadin:vaadin-maven-plugin:24.3.11:prepare-frontend failed: Unable to load the mojo 'prepare-frontend' in the plugin 'com.vaadin:vaadin-maven-plugin:24.3.11' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: com/vaadin/flow/plugin/maven/PrepareFrontendMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
解决方案
一、解决Maven插件Java版本兼容问题
- 统一Maven运行JDK版本:
打开IntelliJ IDEA设置(File → Settings → Build, Execution, Deployment → Build Tools → Maven → Runner),将JRE选项设置为Liberica 17,确保Maven构建时使用的JDK与项目SDK一致。 - 统一Vaadin依赖与插件版本:
检查pom.xml,确保所有Vaadin相关依赖(如vaadin-spring-boot-starter)和Maven插件(vaadin-maven-plugin)的版本完全一致,避免混合24.4.0.beta1和24.3.11版本。例如若选择稳定版24.3.11,需将vaadin.version属性设为24.3.11,插件版本也对应为24.3.11。 - 清理Maven缓存并重新构建:
执行命令:
强制清理本地缓存并重新拉取依赖,确保依赖文件版本正确。./mvnw clean install -U
二、解决运行时空指针异常问题
- 启用Vaadin开发模式:
在src/main/resources/application.properties中添加配置:
开发模式下无需重启应用,修改代码后直接刷新浏览器即可生效,减少重启次数,避免会话状态残留导致的异常。vaadin.devmode.enabled=true - 清理前端生成资源:
删除项目根目录下的node_modules、package.json、package-lock.json文件,以及target/frontend目录,然后执行:
重新生成前端依赖文件,避免旧资源冲突。./mvnw vaadin:prepare-frontend - 强制刷新浏览器并清理会话:
重启应用后,关闭所有相关浏览器标签,打开新标签并按Ctrl+Shift+R强制刷新页面,清除浏览器缓存和旧会话数据。 - 排查依赖冲突:
执行./mvnw dependency:tree查看依赖树,确认项目中没有同时存在不同Vaadin版本的依赖,若有则排除冲突版本。
内容的提问来源于stack exchange,提问作者Svetlana
相关产品推荐
相关产品推荐

