报告应用的自动配置 Spring Boot
💡一则或许对你有用的小广告
欢迎加入小哈的星球 ,你将获得:专属的项目实战 / 1v1 提问 / Java 学习路线 / 学习打卡 / 每月赠书 / 社群讨论
- 新项目:《从零手撸:仿小红书(微服务架构)》 正在持续爆肝中,基于
Spring Cloud Alibaba + Spring Boot 3.x + JDK 17...
,点击查看项目介绍 ;- 《从零手撸:前后端分离博客项目(全栈开发)》 2 期已完结,演示链接: http://116.62.199.48/ ;
截止目前, 星球 内专栏累计输出 82w+ 字,讲解图 3441+ 张,还在持续爆肝中.. 后续还会上新更多项目,目标是将 Java 领域典型的项目都整一波,如秒杀系统, 在线商城, IM 即时通讯,权限管理,Spring Cloud Alibaba 微服务等等,已有 2800+ 小伙伴加入学习 ,欢迎点击围观
Spring Boot 中的自动配置功能根据条件将 bean 添加到我们的应用程序上下文中。例如,基于类路径上类的可用性或环境属性 bean 被启用或禁用。我们必须在我们的 Spring Boot 应用程序中应用
@EnableAutoConfiguration
或
@SpringBootApplicaiton
才能完成这项工作。要概览我们应用程序中所有具有正面和负面条件匹配的配置,我们可以使用
--debug
命令行选项。这将向 System.out 打印一份报告,其中包含完整的概述。我们可以检查为什么应用配置。
在以下 Gradle 构建文件中,我们将选项
--debug
添加到
bootRun
任务的
args
属性:
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'groovy'
apply plugin: 'spring-boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.4'
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-groovy-templates"
compile "org.springframework.boot:spring-boot-starter-web"
runtime "com.h2database:h2"
testCompile "org.springframework.boot:spring-boot-starter-test"
}
bootRun {
// Use --debug option to print out
// auto-configuration report.
args '--debug'
}
让我们运行
bootRun
任务并检查输出(接下来显示的输出中省略了行):