报告应用的自动配置 Spring Boot

一则或许对你有用的小广告

欢迎加入小哈的星球 ,你将获得:专属的项目实战 / Java 学习路线 / 一对一提问 / 学习打卡/ 赠书活动

目前,正在 星球 内带小伙伴们做第一个项目:全栈前后端分离博客项目,采用技术栈 Spring Boot + Mybatis Plus + Vue 3.x + Vite 4手把手,前端 + 后端全栈开发,从 0 到 1 讲解每个功能点开发步骤,1v1 答疑,陪伴式直到项目上线,目前已更新了 204 小节,累计 32w+ 字,讲解图:1416 张,还在持续爆肝中,后续还会上新更多项目,目标是将 Java 领域典型的项目都整上,如秒杀系统、在线商城、IM 即时通讯、权限管理等等,已有 870+ 小伙伴加入,欢迎点击围观

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 任务并检查输出(接下来显示的输出中省略了行):