Spring Bootで自動構成レポートを表示する
1. 概要
Spring Bootの自動構成メカニズムは、依存関係に基づいてアプリケーションを自動的に構成しようとします。
このクイックチュートリアルでは、we’ll see how Spring Boot can log its auto-configuration report at startup time.
2. サンプルアプリケーション
例で使用する簡単なSpringBootアプリケーションを作成しましょう。
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
3. アプリケーションプロパティアプローチ
このアプリケーションを起動する際に、SpringBootがアプリケーションの構成を構成することを決定した方法または理由に関する多くの情報を取得していません。
ただし、application.propertiesファイルのwe can have Spring Boot create a report simply by enabling debug mode:
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がクラスパスで検出して自動的に構成したクラスに関する情報が含まれています。 また、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にあります。