Spring Boot 运行原理 - 查看Spring Boot自动配置项

1 查看Spring Boot自动配置项

Spring Boot 自动配置源代码在spring-boot-autoconfigure-1.5.3.RELEASE.jar内,如图:

《Spring Boot 运行原理 - 查看Spring Boot自动配置项》《Spring Boot 运行原理 - 查看Spring Boot自动配置项》

如果想知道Spring Boot做了那些自动配置可以在这里看源码。

可以通过下面三种方式查看当前项目中已启用和未启动的自动配置报告:

  1. 运行jar时添加–debug参数:
java -jar xx.jar --debug
  1. 在application.properties文件中加属性:
debug=true
  1. 在STS中进行设置,如图:

《Spring Boot 运行原理 - 查看Spring Boot自动配置项》《Spring Boot 运行原理 - 查看Spring Boot自动配置项》

此时启动会在控制台输出,已启用的自动配置:

========================= AUTO-CONFIGURATION REPORT
========================= 

Positive matches:
----------------- 
   DefaultValidatorConfiguration#defaultValidator matched:
      - @ConditionalOnMissingBean (types: javax.validation.Validator,org.springframework.validation.Validator; SearchStrategy: all) did not find any beans (OnBeanCondition) 
   DispatcherServletAutoConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)       - @ConditionalOnWebApplication (required) found StandardServletEnvironment (OnWebApplicationCondition) 
   DispatcherServletAutoConfiguration.DispatcherServletConfiguration matched:
      - @ConditionalOnClass found required class 'javax.servlet.ServletRegistration'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)       - Default DispatcherServlet did not find dispatcher servlet beans (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition) ...

未启用的自动配置:

Negative matches:
----------------- 
   ActiveMQAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 'org.apache.activemq.ActiveMQConnectionFactory' (OnClassCondition) 
   AopAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required classes 'org.aspectj.lang.annotation.Aspect', 'org.aspectj.lang.reflect.Advice' (OnClassCondition) ...

以排除的自动配置

Exclusions: -----------

 None

无条件类:

Unconditional classes:
----------------------

    org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration

    org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration

    org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration

    org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration

《Spring Boot 运行原理 - 查看Spring Boot自动配置项》

    原文作者:Spring Boot
    原文地址: https://blog.csdn.net/xiaolyuh123/article/details/70808929
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞