Loading...

September 17, 2015

Spring Sweets: Report Applied Auto-configuration Spring Boot

The auto-configuration feature in Spring Boot adds beans to our application context based on conditions. For example based on the availability of a class on the class path or a environment property beans are enabled or disabled. We must apply the @EnableAutoConfiguration or @SpringBootApplicaiton in our Spring Boot application to make this work. To get an overview of all the configurations that had positive and negative conditional matches in our application we can use the --debug command-line option. This will print out a report to System.out with a complete overview. We can check why a configuration is applied or not.

In the following Gradle build file we add the option --debug to the args property of the bootRun task:

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'
}

Let's run the bootRun task and check the output (lines are omitted in the output shown next):

$ gradle bootRun
...
=========================
AUTO-CONFIGURATION REPORT
=========================


Positive matches:
-----------------

...
   GroovyTemplateAutoConfiguration
      - @ConditionalOnClass classes found: groovy.text.markup.MarkupTemplateEngine (OnClassCondition)

   GroovyTemplateAutoConfiguration.GroovyMarkupConfiguration
      - @ConditionalOnClass classes found: org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer (OnClassCondition)

   GroovyTemplateAutoConfiguration.GroovyMarkupConfiguration#groovyMarkupConfigurer
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.groovy.GroovyMarkupConfig; SearchStrategy: all) found no beans (OnBeanCondition)

   GroovyTemplateAutoConfiguration.GroovyWebConfiguration
      - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.context.i18n.LocaleContextHolder,org.springframework.web.servlet.view.UrlBasedViewResolver (OnClassCondition)
      - found web application StandardServletEnvironment (OnWebApplicationCondition)
      - matched (OnPropertyCondition)

   GroovyTemplateAutoConfiguration.GroovyWebConfiguration#groovyMarkupViewResolver
      - @ConditionalOnMissingBean (names: groovyMarkupViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)
...

Negative matches:
-----------------

   ActiveMQAutoConfiguration
      - required @ConditionalOnClass classes not found: javax.jms.ConnectionFactory,org.apache.activemq.ActiveMQConnectionFactory (OnClassCondition)
...
$

Written with Spring Boot 1.2.5.RELEASE