You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移至Spring 6.0.0后因缺失NestedIOException类启动失败

Spring 6.0.0迁移启动失败问题分析与解决

问题场景

原应用在Spring Boot 3.1.0 + Java 17环境下运行正常,手动升级以下Spring核心依赖至6.0.0版本后,应用无法启动:

implementation 'org.springframework:spring-core:6.0.0'
implementation 'org.springframework:spring-beans:6.0.0'
implementation 'org.springframework:spring-expression:6.0.0'
implementation 'org.springframework:spring-webflux:6.0.0'
implementation 'org.springframework:spring-webmvc:6.0.0'
implementation 'org.springframework:spring-web:6.0.0'

报错日志

2023-06-10 23:17:34.892 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:312)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at rf.dom.billing.ap.Application.main(Application.java:24)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.NestedIOException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 25 common frames omitted

问题原因

  1. 类移除兼容问题:org.springframework.core.NestedIOException在Spring 6.0版本中被移除,该类功能已合并到JDK标准异常(如IOException子类)中,旧代码或依赖库若仍引用该类会触发ClassNotFoundException。
  2. 依赖版本冲突:手动单独指定Spring模块版本为6.0.0,破坏了Spring Boot父POM的版本管理机制,导致部分依赖(如Spring Cloud组件)与Spring核心版本不兼容——日志中出现的BootstrapApplicationListener属于Spring Cloud,旧版本Spring Cloud可能仍依赖已被移除的NestedIOException。
  3. 版本匹配问题:Spring Boot 3.1.0默认依赖Spring 6.0.x系列,但手动指定固定6.0.0版本,可能与Spring Boot内置的其他依赖存在细微冲突。

解决方案

1. 依赖版本交由Spring Boot父POM管理

删除手动指定的Spring核心模块版本,依赖Spring Boot父项目统一管理所有Spring相关依赖版本,避免版本冲突:

// 确保项目继承Spring Boot父POM
plugins {
    id 'org.springframework.boot' version '3.1.0'
    id 'io.spring.dependency-management' version '1.1.0'
    // 其他插件
}

dependencies {
    // 无需手动指定Spring模块版本,由父POM自动管理
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    // 其他依赖
}

2. 升级Spring Cloud至兼容版本

Spring Boot 3.1.0对应的兼容Spring Cloud版本为2022.0.x(代号Kilburn),确保版本匹配:

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:2022.0.3"
    }
}

3. 替换代码中对NestedIOException的引用

如果项目代码直接使用了NestedIOException,替换为JDK标准异常类:

// 旧代码
throw new NestedIOException("文件读取失败", e);

// 替换为
throw new IOException("文件读取失败", e);

内容的提问来源于stack exchange,提问作者Eljah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 09:50:01