selectImports:<br>解决装配什么<br>
入参AnnotationMetadata:<br>注解元信息
AnnotationAttributes:<br>getAttributes(annotationMetadata)获取注解属性信息<br>
getCandidateConfigurations:<br>获取候选配置类
找EnableAutoConfiguration定义信息:<br>"META-INF/spring.factories"<br>
以MultiValueMap<String, String>形式存入缓存
配置类例子:<br>@Import({ JdbcTemplateConfiguration.class, NamedParameterJdbcTemplateConfiguration.class })<br>JdbcTemplateAutoConfiguration<br>
JdbcTemplateConfiguration: <br> @Bean<br> @Primary<br> JdbcTemplate jdbcTemplate(DataSource dataSource, JdbcProperties properties) {<br> JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);<br> JdbcProperties.Template template = properties.getTemplate();<br> jdbcTemplate.setFetchSize(template.getFetchSize());<br> jdbcTemplate.setMaxRows(template.getMaxRows());<br> if (template.getQueryTimeout() != null) {<br> jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());<br> }<br> return jdbcTemplate;<br> }<br>
removeDuplicates:<br>配置类去重
getExclusions:<br>获得待排除的类
exclude
例子(多个时逗号隔开):<br>exclude = {DataSourceAutoConfiguration.class}<br>
excludeName
例子(需是类的全限定名,多个时逗号隔开):<br>excludeName = {"org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration"<br>
spring.autoconfigure.exclude
checkExcludedClasses:<br>校验待排除的类
判断要排除的类是否是自动装配配置类,不是则抛出异常
IllegalStateException:<br>"The following classes could not be excluded <br>because they are not auto-configuration classes:%n%s"<br>
配置类列表删除要排除的部分
配置类列表再次过滤
过滤器定义:<br>\META-INF\spring.factories<br>
过滤器例子:<br># Auto Configuration Import Filters<br>org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\<br>org.springframework.boot.autoconfigure.condition.OnBeanCondition,\<br>org.springframework.boot.autoconfigure.condition.OnClassCondition,\<br>org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition<br>
作用:如果一个配置类依赖某个class,<br>但是这个class在classpath下找不到,<br>则这个配置类会被过滤,即不会作为自动装配对象<br>
启动日志(debug: true):<br>Negative matches<br>
RedisCacheConfiguration:<br> Did not match:<br> - @ConditionalOnClass did not find required class <br>'org.springframework.data.redis.connection.RedisConnectionFactory' (OnClassCondition)<br>
fireAutoConfigurationImportEvents<br>
new AutoConfigurationImportEvent
AutoConfigurationImportListener
listener.onAutoConfigurationImportEvent(event):<br>将配置类数组保存到监听器的一个对象
默认配置类定义文件例子:<br>\spring-boot-autoconfigure-2.3.12.RELEASE.jar!\META-INF\spring.factories<br>