Показывать отчет автоконфигурации в Spring Boot

Отобразить отчет автоконфигурации в Spring Boot

1. обзор

Механизм автоматической настройки в Spring Boot пытается автоматически настроить приложение на основе его зависимостей.

В этом кратком руководствеwe’ll see how Spring Boot can log its auto-configuration report at startup time.

2. Образец заявки

Давайте напишем простое приложение Spring Boot, которое мы будем использовать в наших примерах:

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

3. Подход свойств приложения

Запуская это приложение, мы не получаем много информации о том, как и почему Spring Boot решил составить конфигурацию нашего приложения.

Ноwe can have Spring Boot create a report simply by enabling debug mode в нашем файлеapplication.properties:

debug=true

Или наш файлapplication.yml:

debug: true

4. Командная строка

Или, если мы не хотим использовать подход файла свойств, мы можем активировать отчет автоконфигурации с помощьюstarting the application with the –debug switch:

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

5. Вывод отчета

Отчет автоконфигурации содержит информацию о классах, которые Spring Boot обнаружил в classpath и настроил автоматически. Он также показывает информацию о классах, которые известны Spring Boot, но не найдены в пути к классам.

И поскольку мы установили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. Заключение

В этом кратком руководстве мы увидели, как отобразить и прочитать отчет автоматической конфигурации Spring Boot.

И, как всегда, исходный код для приведенного выше примера можно найтиover on GitHub.