spring boot 扩展之AutoConfigurationImportListener
最近阅读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的更多相关文章
- Spring Boot 扩展点应用之工厂加载机制
Spring 工厂加载机制,即 Spring Factories Loader,核心逻辑是使用 SpringFactoriesLoader 加载由用户实现的类,并配置在约定好的META-INF/spr ...
- 精尽Spring Boot源码分析 - Condition 接口的扩展
该系列文章是笔者在学习 Spring Boot 过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring Boot 源码分析 GitHub 地址 进行阅读 Sprin ...
- Spring Boot 自动装配(二)
目录 目录 前言 1.起源 2.Spring Boot 自动装配实现 2.1.@EnableAutoConfiguration 实现 2.1.1. 获取默认包扫描路径 2.1.2.获取自动装配的组件 ...
- Spring Boot 启动原理分析
https://yq.aliyun.com/articles/6056 转 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启 ...
- Spring Boot 实战与原理分析视频课程
Spring Boot 实战与原理分析视频课程 链接:https://pan.baidu.com/share/init?surl=PeykcoeqZtd1d9lN9V_F-A 提取码: 关注公众号[G ...
- Spring Boot实践——事件监听
借鉴:https://blog.csdn.net/Harry_ZH_Wang/article/details/79691994 https://blog.csdn.net/ignorewho/arti ...
- spring boot应用启动原理分析
spring boot quick start 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启动的,不需要另外配置一个We ...
- Spring Boot应用启动原理分析(转)
在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启动的,不需要另外配置一个Web Server. 如果之前没有使用过sprin ...
- Spring boot参考指南
介绍 转载自:https://www.gitbook.com/book/qbgbook/spring-boot-reference-guide-zh/details 带目录浏览地址:http://ww ...
随机推荐
- Codeforces 938.D Buy a Ticket
D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- command not found: django-admin.py
http://www.cnblogs.com/Xjng/p/3559984.html django-admin.py startproject projectname 其中projectname 为 ...
- Bash to check SSL cert expired
Code like this, You can send out a email to notice $ cat urls.txt www.baidu.com $ cat cert_chk.sh #! ...
- JS中client/offset/scroll等的宽高解析
原文地址:→传送门 window相关宽高属性 1. window.outerHeight (窗口的外层的高度) / window.outerWidth (窗口的外层的宽度) window.outerH ...
- 重构改善既有代码设计--重构手法07:Remove Assignments to Parameters (移除对参数的赋值)
代码对一个 参数赋值.以一个临时变量取代该参数的位置. int Discount(int inputVal, int quantity, int yearTodate) { if (input ...
- 更改gradle的java的class文件输出目录的结构
group 'com.thinkvenus.common'version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 r ...
- js和php的时间戳和时间的转化
js时间戳转化为时间 //时间戳转时间 function time(sj) { var now = new Date(sj*1000); var year =now.getFullYear(); va ...
- Html符号
- Kali设置代理
原文:Kali-linux设置ProxyChains ProxyChains是Linux和其他Unices下的代理工具.它可以使任何程序通过代理上网,允许TCP和DNS通过代理隧道,支持HTTP.SO ...
- vps建站教程 CentOS6如何安装配置FTP服务器
通过之前的几篇文章,我们都知道了如何配置PHP环境,也知道如何保护我们的vps以及如何绑定多个域名建设多个网站.有时候我们为了让我们的朋友也能用我们的vps建站又不想给他们太多权限,有时候我们想要当个 ...