jHipster 8.0.0-rc.1网关应用启动失败,求助解决方案
启动jHipster 8.0.0-rc.1网关应用时出现ApplicationContext初始化失败,核心错误信息如下:
启动ApplicationContext时出错。如需显示条件评估报告,请启用'debug'模式重新运行应用。
2023-10-20T17:33:24.634+05:30 ERROR 28508 --- [ restartedMain] o.s.boot.SpringApplication : 应用运行失败
org.springframework.beans.factory.BeanCreationException: 创建类路径资源[org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]中定义的名为'stompWebSocketHandlerMapping'的Bean时出错:无法实例化[org.springframework.web.servlet.HandlerMapping]:工厂方法'stompWebSocketHandlerMapping'抛出异常,消息为:jakarta/websocket/Endpoint
对应的JDL配置:
application { config { enableTranslation true applicationType gateway serviceDiscoveryType consul languages [en, hi, te] nativeLanguage en packageName in.beze.pc testFrameworks [gatling, cucumber, protractor] websocket spring-websocket baseName pc serverPort 8080 jhiPrefix sys prodDatabaseType postgresql devDatabaseType postgresql databaseType sql cacheProvider ehcache enableHibernateCache true authenticationType session buildTool gradle clientPackageManager npm clientFramework angularX } entities * } application { config { baseName masters applicationType microservice packageName in.beze.masters serviceDiscoveryType consul authenticationType session prodDatabaseType postgresql devDatabaseType postgresql databaseType sql buildTool gradle serverPort 8081 skipUserManagement true cacheProvider ehcache enableHibernateCache true websocket spring-websocket } entities Attachment, ContentType, Equipment, EquipmentType, FacilityType, FacilityGroupType, FacilityGroup, Facility, FacilityHistory, FacilityUser, FacilityAttachment, FacilityEquipment, FrequencyType, Frequency, Gender, JobSandbox, Language, Party, Permission, PermissionAuthority, ProductStoreType, ProductStore, ProductStoreFacility, ProductStoreUserGroup, Responsibility, RoleType, Scheduler, StatusCategory, Status, StatusValidChange, UserRole, UserGroup, UserGroupAuthority, UserGroupMember, Uom, UomType, UserAttachment, SystemParameters, QRCode, QRCodeType, QRCodeAttachment, Product, ProductType, ProductCategoryType, ProductCategory, ProductCategoryMember, Stage, ProductSpecGroup, ProductSpec, ProductSpecItem, StabilityCondition, StabilityConditionAttachment } application { config { baseName stability applicationType microservice packageName in.beze.stability serviceDiscoveryType consul authenticationType session prodDatabaseType postgresql devDatabaseType postgresql databaseType sql buildTool gradle serverPort 8082 skipUserManagement true cacheProvider ehcache enableHibernateCache true websocket spring-websocket } entities StAttachment, StContentType, AnalysisType, SpEquipment, SsEquipment, SpProductSpec, StabilityProgramme, StabilityAttachment, SampleType, StabilitySample, SampleResult, SampleAttachment, SampleResultAttachment, EquipmentSc }
已尝试更换Java版本,但问题未解决。
该错误核心原因是Jakarta WebSocket API相关依赖缺失或版本不匹配——jHipster 8基于Spring Boot 3,全面切换到Jakarta EE规范,不再兼容旧的Java EE包。可按以下步骤排查修复:
- 强制使用Java 17及以上版本:Spring Boot 3和jHipster 8要求最低Java 17,低于该版本无法正确加载Jakarta相关类,确认环境变量和项目配置的Java版本符合要求。
- 检查Gradle依赖配置:在网关项目的
build.gradle中,确保已正确引入Spring Boot WebSocket Starter,且版本与Spring Boot 3.x匹配:
若存在自定义WebSocket依赖,需确保使用Jakarta版本(如implementation 'org.springframework.boot:spring-boot-starter-websocket'jakarta.websocket:jakarta.websocket-api),而非旧的javax.websocket包。 - 清理缓存并重建项目:执行以下命令清除构建缓存、重新下载依赖,避免依赖冲突或缓存损坏:
./gradlew clean build - 检查自定义WebSocket代码:如果项目中有自定义的WebSocket配置类或端点代码,确认导入的是Jakarta包:
import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpoint; // 禁止使用旧的 javax.websocket.* 包 - 升级jHipster版本:由于使用的是8.0.0-rc.1候选版本,可能存在已知配置bug,建议升级到最新的jHipster 8稳定版,修复可能的依赖配置问题。
内容的提问来源于stack exchange,提问作者Vicky

