springboot Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled
时间: 2025-08-13 22:59:22 AIGC 浏览: 18
在Spring Boot应用启动过程中,如果出现 `Error starting ApplicationContext` 错误,并且提示 `To display the conditions report re-run your application with 'debug' enabled`,这意味着可以通过启用 **debug 模式** 来获取详细的 **条件评估报告**(Conditions Report),从而帮助定位问题根源。
### 如何启用 debug 模式以查看条件评估报告
#### 方法一:通过命令行参数启用 debug 模式
在启动 Spring Boot 应用时,可以通过添加 `--debug` 参数来启用 debug 模式。例如:
```bash
java -jar your-application.jar --debug
```
如果使用的是 Maven 插件运行应用,可以使用以下命令:
```bash
mvn spring-boot:run -Drun.arguments="--debug"
```
#### 方法二:在 `application.properties` 或 `application.yml` 中配置 debug 模式
也可以在配置文件中设置 `debug=true` 来启用 debug 模式:
**application.properties**
```properties
debug=true
```
**application.yml**
```yaml
debug: true
```
启用 debug 模式后,控制台会输出详细的条件评估报告,其中包括:
- 每个自动配置类是否被匹配(Matched)或未被匹配(Unmatched)。
- 未匹配的原因(例如缺少依赖、缺少配置属性等)。
- 各个自动配置条件的评估结果。
#### 示例输出片段
当启用 debug 模式后,控制台会显示如下格式的条件评估报告:
```
============================
CONDITIONS EVALUATION REPORT
============================
Positive matches:
-----------------
DataSourceAutoConfiguration matched:
- @ConditionalOnClass found required class 'javax.sql.DataSource'
- @ConditionalOnMissingBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans
Negative matches:
-----------------
H2ConsoleAutoConfiguration:
Did not match:
- @ConditionalOnClass did not find required class 'org.h2.server.web.WebServlet'
```
### 常见导致 ApplicationContext 启动失败的原因
结合引用内容,以下是一些常见的启动失败原因:
- **未正确配置数据源**:例如缺少 `url`、`username`、`password` 或未指定数据库驱动类[^3]。
- **依赖缺失**:如未引入嵌入式数据库(H2、Derby 等)依赖[^3]。
- **构建配置错误**:如 WAR 包部署时未正确排除内嵌 Tomcat 依赖或未引入外部 Tomcat 支持[^4]。
- **未激活配置文件**:如数据库配置依赖特定 profile,但未激活该 profile[^3]。
启用 debug 模式后,可以通过条件评估报告快速定位是哪个自动配置类未能正确加载,以及具体原因。
阅读全文
相关推荐

















