最近阅读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 932.D Tree

    D. Tree time limit per test 2 seconds memory limit per test 512 megabytes input standard input outpu ...

  2. Codeforces Round #546 (Div. 2) ABCDE 题解

    1136A: 题意:一本书有n个章节,每个章节的分别在li到ri页,小明读完书后将书折在第k页,问还有多少章节没有读 题解:控制k在li~ri的范围内后输出n-i即可 #include <set ...

  3. 010. C++ 传值与传引用

    1.参数传递 参数传递:pass by value vs. pass by reference(to const) 推荐:能传引用,尽量传引用(高效,尤其在需要拷贝的对象很大时) class comp ...

  4. Python学习笔记(2.1)函数参数练习

    关键字参数 和 命名关键字参数 # -*- coding: utf-8 -*- def print_scores(**kw): print(' Name Score') print('-------- ...

  5. cocos2dx学习,转摘一些链接

    cocos2d-x学习笔记09:动作2:持续动作 ccBezierConfig 贝塞尔坐标点是相对的 Box2DTestBed很有意思的demo,可惜自己水平有限针对其实现还是没弄明白,以后有时间多学 ...

  6. 论文里有公式?用texlive+texstudio(windows下)

    要写论文了,但论文里有一大堆公式,感觉很麻烦,经过询问同学知道有tex这么个东西,可以像写代码一样写论文,许多论文的格式都有相关的模板,所以学习一下,这里记录一下环境安装. texlive和texst ...

  7. c语言学习笔记.条件编译.#if,#ifdef,if的区别

    最近遇到了,以此做个记录. 条件编译 是C预处理部分的内容. 其判断语句包括 #if  #else if  #else 以及 #ifdef 和 #endif. 使用 #if (表达式) codes1. ...

  8. makefile使用.lds链接脚本以及 $@ ,$^, $,< 解析【转】

    转自:http://www.cnblogs.com/lifexy/p/7089873.html 先来分析一个简单的.lds链接脚本 例1,假如现在有head.c init.c nand.c main. ...

  9. 树莓派开发系列教程3--ssh、vnc远程访问

    注意:树莓派系列的3篇文章里面的图片因为博客转移过程丢失了,非常抱歉 前言 远程访问有很多种方式可以实现.比如ssh.telnet.ftp.samba.远程桌面等等,各有优缺点.本文主要以ssh和远程 ...

  10. React 16 源码瞎几把解读 【二】 react组件的解析过程

    一.一个真正的react组件编译后长啥样? 我们瞎几把解读了react 虚拟dom对象是怎么生成的,生成了一个什么样的解构.一个react组件不光由若干个这些嵌套的虚拟dom对象组成,还包括各种生命周 ...