Display Auto-Configuration Report in Spring Boot – 在Spring Boot中显示自动配置报告

最后修改: 2018年 10月 18日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

The auto-configuration mechanism in Spring Boot attempts to automatically configure an application based on its dependencies.

Spring Boot中的自动配置机制试图根据应用程序的依赖关系来自动配置它。

In this quick tutorial, we’ll see how Spring Boot can log its auto-configuration report at startup time.

在这个快速教程中,我们将看到Spring Boot如何在启动时记录其自动配置报告。

2. Sample Application

2.应用样本

Let’s write a simple Spring Boot application that we’ll use in our examples:

让我们写一个简单的Spring Boot应用程序,我们将在我们的例子中使用。

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

3. Application Properties Approach

3.应用属性方法

In starting up this application, we don’t get a lot of information about how or why Spring Boot decided to compose our application’s configuration.

在启动这个应用程序时,我们并没有得到很多关于Spring Boot如何或为什么决定组成我们应用程序的配置的信息。

But, we can have Spring Boot create a report simply by enabling debug mode in our application.properties file:

但是,我们可以通过在application.properties文件中启用调试模式,让Spring Boot创建一个报告。

debug=true

Or our application.yml file:

或者我们的application.yml文件。

debug: true

4. Command-Line Approach

4.命令行的方法

Or, if we don’t want to use the properties file approach, we can trigger the auto-configuration report by starting the application with the –debug switch:

或者,如果我们不想使用属性文件的方法,我们可以通过-debug开关启动应用程序来触发自动配置报告。

$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug

5. Report Output

5.报告输出

The auto-configuration report contains information about the classes that Spring Boot found on the classpath and configured automatically. It also shows information about classes that are known to Spring Boot but were not found on the classpath.

自动配置报告包含有关Spring Boot在classpath上发现并自动配置的类的信息。它还显示了Spring Boot已知但在classpath上没有发现的类的信息。

And, because we’ve set debug=true, then we see it in our output:

而且,因为我们设置了debug=true,所以我们在输出中看到它。

============================
CONDITIONS EVALUATION REPORT
============================


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

   AopAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'org.springframework.context.annotation.EnableAspectJAutoProxy', 
        'org.aspectj.lang.annotation.Aspect', 'org.aspectj.lang.reflect.Advice', 'org.aspectj.weaver.AnnotatedElement'; 
        @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
      - @ConditionalOnProperty (spring.aop.auto=true) matched (OnPropertyCondition)

   AopAutoConfiguration.CglibAutoProxyConfiguration matched:
      - @ConditionalOnProperty (spring.aop.proxy-target-class=true) matched (OnPropertyCondition)

   AuditAutoConfiguration#auditListener matched:
      - @ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.listener.AbstractAuditListener; 
        SearchStrategy: all) did not find any beans (OnBeanCondition)

   AuditAutoConfiguration.AuditEventRepositoryConfiguration matched:
      - @ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventRepository; 
        SearchStrategy: all) did not find any beans (OnBeanCondition)

   AuditEventsEndpointAutoConfiguration#auditEventsEndpoint matched:
      - @ConditionalOnBean (types: org.springframework.boot.actuate.audit.AuditEventRepository; 
        SearchStrategy: all) found bean 'auditEventRepository'; 
        @ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventsEndpoint; 
        SearchStrategy: all) did not find any beans (OnBeanCondition)
      - @ConditionalOnEnabledEndpoint no property management.endpoint.auditevents.enabled found 
        so using endpoint default (OnEnabledEndpointCondition)


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

   ActiveMQAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 
           'org.apache.activemq.ActiveMQConnectionFactory' (OnClassCondition)

   AopAutoConfiguration.JdkDynamicAutoProxyConfiguration:
      Did not match:
         - @ConditionalOnProperty (spring.aop.proxy-target-class=false) did not find property 
           'proxy-target-class' (OnPropertyCondition)

   ArtemisAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 
           'org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory' (OnClassCondition)

   AtlasMetricsExportAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'io.micrometer.atlas.AtlasMeterRegistry' 
           (OnClassCondition)

   AtomikosJtaConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'com.atomikos.icatch.jta.UserTransactionManager' 
           (OnClassCondition)

6. Conclusion

6.结论

In this quick tutorial, we saw how to display and read a Spring Boot auto-configuration report.

在这个快速教程中,我们看到如何显示和阅读Spring Boot自动配置报告。

And as always, the source code for the above example can be found over on GitHub.

和往常一样,上述例子的源代码可以在GitHub上找到