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

SpringApplication.run报错:ConfigurableApplicationContext无法解析求助

解决SpringApplication.run报错:无法解析ConfigurableApplicationContext的问题

嘿,我之前也踩过这个一模一样的坑!这个报错的核心原因很明确——你的项目里缺失了Spring Context模块的核心依赖,或者依赖版本冲突、IDE缓存没同步,导致ConfigurableApplicationContext这个类找不到(毕竟SpringApplication.run()方法的返回值就是这个类型)。

给你几个一步步排查解决的方案:

1. 检查pom.xml的基础依赖是否正确

Spring Boot项目的核心依赖都靠starter包来管理,你得确保引入了最基础的spring-boot-starter(或者对应场景的starter,比如Web项目用spring-boot-starter-web)。它会自动帮你引入包括spring-context在内的所有必要核心依赖,不用手动一个个加。

正确的依赖配置示例:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

如果是Web项目,换成这个更合适:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2. 确保依赖版本统一(用Spring Boot父依赖管理)

如果你手动指定了Spring或Spring Boot的版本,很容易出现版本冲突。最稳妥的方式是用Spring Boot的父依赖来自动管理所有依赖版本,避免版本不一致的问题:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <!-- 换成你要用的Spring Boot版本,比如2.7.15或者3.2.0 -->
    <version>2.7.15</version>
    <relativePath/>
</parent>

3. 彻底刷新Maven依赖(比单独purge更有效)

你已经试过mvn dependency:purge-local-repository,但可以配合clean、install和强制更新参数一起执行,确保本地仓库的依赖是干净且最新的:

mvn clean dependency:purge-local-repository install -U

-U参数会强制Maven更新快照依赖,避免本地缓存的旧依赖搞事情。

4. 清空IDE缓存并重新加载项目

有时候Maven依赖已经正确了,但IDE的缓存没同步,导致还是报错。以IntelliJ IDEA为例:

  • 点击File -> Invalidate Caches...,选择Invalidate and Restart,重启IDE清空缓存
  • 或者右键项目 -> Maven -> Reload Project,让IDE重新读取pom.xml并同步依赖

5. 排查是否有依赖排除导致的问题

有些第三方依赖可能会自动排除spring-context模块,这也会导致核心类缺失。你可以用Maven命令查看完整的依赖树,找出异常的排除项:

mvn dependency:tree

如果发现某个依赖排除了spring-context,可以在你的pom.xml里手动添加该依赖,或者调整第三方依赖的版本。

按照这些步骤走下来,基本能解决这个问题啦!如果还是不行,把你的pom.xml内容贴出来,我再帮你进一步排查~

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:20:03