Spring Boot 2.7.18升级至3.1.0时SCDF应用启动报错求助
问题场景
升级SCDF应用从Spring Boot 2.7.18到3.1.0后,启动抛出如下错误:
java.lang.NoClassDefFoundError: org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontProperties at org.springframework.cloud.dataflow.server.config.MetricsReplicationEnvironmentPostProcessor.postProcessEnvironment(MetricsReplicationEnvironmentPostProcessor.java:107)
类路径中存在org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties,但旧包路径的类始终找不到。
问题原因
Spring Boot 3.0+对Wavefront监控相关的配置类包结构做了调整:
- Spring Boot 2.x中,
WavefrontProperties的路径是org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontProperties - Spring Boot 3.x中,该类被迁移到了
org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties
当前使用的SCDF版本未适配Spring Boot 3.x的包结构变化,导致MetricsReplicationEnvironmentPostProcessor仍在尝试加载旧路径的类。
解决方案
同步升级SCDF到兼容版本
Spring Boot 3.x需要搭配SCDF 2.11.x及以上版本使用,若当前SCDF版本过低,直接升级到对应兼容版本即可解决类路径引用问题。修正自定义代码中的类引用(如果有)
若项目中自定义了引用WavefrontProperties的代码,或者修改过MetricsReplicationEnvironmentPostProcessor,将所有旧包路径的引用替换为新路径:
把import org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontProperties;
替换为import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;清理依赖缓存并重新构建
执行构建工具的清理命令(比如Maven的mvn clean install,Gradle的clean build),清除本地缓存的旧依赖,确保新的包路径类被正确引入到类路径中。
内容的提问来源于stack exchange,提问作者anudeep kn

