最近阅读spring boot源码时发现,发现当spring使用ConfigurationClassParser加载使用@Configuration注解类后,会使用AutoConfigurationImportSelector对加载的

@Configuration注解的类进行一次过滤。当AutoConfigurationImportSelector过滤完成后会自动加载类路径下Jar包中META-INF/spring.factories文件中 AutoConfigurationImportListener的实现类

并触发fireAutoConfigurationImportEvents事件。

 实现AutoConfigurationImportListener接口,当fireAutoConfigurationImportEvents事件被触发时,打印出已经注册到spring上下文中的@Configuration注解的类,打印出被阻止注册到spring

上下文中的@Configuration注解类

 package com.torlight;

 import org.springframework.boot.autoconfigure.AutoConfigurationImportEvent;
import org.springframework.boot.autoconfigure.AutoConfigurationImportListener; public class SysoutAutoConfigurationImportListener implements
AutoConfigurationImportListener { @Override
public void onAutoConfigurationImportEvent(
AutoConfigurationImportEvent event) { System.out.println("================output print registered configurations");
for(String str:event.getCandidateConfigurations()){
System.out.println(">>> the configuration => "+ str +" has registered ");
} System.out.println("================output print exclusions configurations");
for(String str:event.getExclusions()){
System.out.println(">>> the configuration =>"+ str +" has exclusion ");
} } }

在src/main/resources/META-INF/spring.factories 文件中增加

org.springframework.boot.autoconfigure.AutoConfigurationImportListener=com.torlight.SysoutAutoConfigurationImportListener

控制台输出:

================output print registered configurations
>>> the configuration => org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration has registered
>>> the configuration => org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.AuditAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.CacheStatisticsAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.InfoContributorAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.EndpointMBeanExportAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.MetricExportAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.TraceRepositoryAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.autoconfigure.TraceWebFilterAutoConfiguration has registered
>>> the configuration => org.springframework.boot.actuate.cloudfoundry.CloudFoundryActuatorAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.aop.AopAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration has registered
>>> the configuration => org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration has registered
>>> the configuration => org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration has registered
>>> the configuration => org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration has registered
>>> the configuration => org.springframework.boot.devtools.autoconfigure.RemoteDevToolsAutoConfiguration has registered
================output print exclusions configurations
>>> the configuration =>org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration has exclusion

spring boot 扩展之AutoConfigurationImportListener的更多相关文章

  1. Spring Boot 扩展点应用之工厂加载机制

    Spring 工厂加载机制,即 Spring Factories Loader,核心逻辑是使用 SpringFactoriesLoader 加载由用户实现的类,并配置在约定好的META-INF/spr ...

  2. 精尽Spring Boot源码分析 - Condition 接口的扩展

    该系列文章是笔者在学习 Spring Boot 过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring Boot 源码分析 GitHub 地址 进行阅读 Sprin ...

  3. Spring Boot 自动装配(二)

    目录 目录 前言 1.起源 2.Spring Boot 自动装配实现 2.1.@EnableAutoConfiguration 实现 2.1.1. 获取默认包扫描路径 2.1.2.获取自动装配的组件 ...

  4. Spring Boot 启动原理分析

    https://yq.aliyun.com/articles/6056 转 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启 ...

  5. Spring Boot 实战与原理分析视频课程

    Spring Boot 实战与原理分析视频课程 链接:https://pan.baidu.com/share/init?surl=PeykcoeqZtd1d9lN9V_F-A 提取码: 关注公众号[G ...

  6. Spring Boot实践——事件监听

    借鉴:https://blog.csdn.net/Harry_ZH_Wang/article/details/79691994 https://blog.csdn.net/ignorewho/arti ...

  7. spring boot应用启动原理分析

    spring boot quick start 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启动的,不需要另外配置一个We ...

  8. Spring Boot应用启动原理分析(转)

    在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启动的,不需要另外配置一个Web Server. 如果之前没有使用过sprin ...

  9. Spring boot参考指南

    介绍 转载自:https://www.gitbook.com/book/qbgbook/spring-boot-reference-guide-zh/details 带目录浏览地址:http://ww ...

随机推荐

  1. Codeforces Round #338 (Div. 2) B dp

    B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  2. 服务器上 tomcat 配置了 tomcat-users 但是还是 403 的问题

    默认情况下,tomcat 限制了只能本机访问 如果我们想要修改这个设置: 编辑 webapps/manager/META-INF/context.xml <!--<Valve classN ...

  3. Jenkins使用教程之管理节点

    通常的情况下在我们的一个项目当中,项目会有多个分支系统,而我们不可能为每个分支系统都配置一个jenkins服务,这样既浪费资源,也增加构建部署的难度,为了解决这个问题jenkins给使用者提供了非常强 ...

  4. NOIP模拟6

    期望得分:100+100+100=300 实际得分:0+100+90=190 T1 superman 二分给每条边加多少,判断是否存在负环 #include<queue> #include ...

  5. Spring Boot 使用IntelliJ IDEA创建一个web开发实例(二)

    1. 创建一个Controller类 package com.example.demo; import org.springframework.web.bind.annotation.RequestM ...

  6. AJAX流程

    创建一个XHR对象 var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari ...

  7. 【BZOJ】1741: [Usaco2005 nov]Asteroids 穿越小行星群

    [题意]给定n*n网格,有k个物品,每次可以消灭一行或一列,求消灭掉所有物品的最少操作次数. [算法]二分图最小覆盖 [题解]此题是最小覆盖模型的出处. 将物品的x-y连边建立二分图. 最小覆盖:选择 ...

  8. 【CodeForces】698 C. LRU

    [题目]C. LRU [题意]给定空间为k的背包和n个物品,每次每个物品有pi的概率加入(Σpi=1),加入时若发现背包中已有该物品则不改变,若背包满k个物品后再加入新物品则弹出最早加入的物品,求加入 ...

  9. 2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)

    题目链接 Problem Description The school set up three elective courses, assuming that these courses are A ...

  10. ubuntu sudoers改坏了。

    pkexec bash 通过如上命令,可以进入root模式,然后恢复sudoers.前提是root账户没被禁用. precise (1) pkexec.1.gz Provided by: policy ...