当前位置: 首页 > news >正文

广告平面设计网站关键词林俊杰免费听

广告平面设计网站,关键词林俊杰免费听,如何设置wordpress的文章分类,网站建设文件名在SpringBoot中,EnableAutoConfiguration注解用于开启自动装配功能。 本文将详细分析该注解的工作流程。 EnableAutoConfiguration注解 启用SpringBoot自动装配功能,尝试猜测和配置可能需要的组件Bean。 自动装配类通常是根据类路径和定义的Bean来应…

在SpringBoot中,EnableAutoConfiguration注解用于开启自动装配功能。

本文将详细分析该注解的工作流程。

EnableAutoConfiguration注解

启用SpringBoot自动装配功能,尝试猜测和配置可能需要的组件Bean。

自动装配类通常是根据类路径和定义的Bean来应用的。例如,如果类路径上有tomcat-embedded.jar,那么可能需要一个TomcatServletWebServerFactory(除非已经定义了自己的Servlet WebServerFactory Bean)。

自动装配试图尽可能地智能化,并将随着开发者定义自己的配置而取消自动装配相冲突的配置。开发者可以使用exclude()排除不想使用的配置,也可以通过spring.autoconfig.exclude属性排除这些配置。自动装配总是在用户定义的Bean注册之后应用。

用@EnableAutoConfiguration注解标注的类所在包具有特定的意义,通常用作默认扫描的包。通常建议将@EnableAutoConfiguration(如果没有使用@SpringBootApplication注解)放在根包中,以便可以搜索所有子包和类。

自动装配类是普通的Spring @Configuration类,使用SpringFactoriesLoader机制定位。通常使用@Conditional方式装配,最常用的是@ConditionalOnClass和@ConditionalOnMissingBean注解。

@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {/*** Exclude specific auto-configuration classes such that they will never be applied.*/Class<?>[] exclude() default {};/*** Exclude specific auto-configuration class names such that they will never be* applied.* 当类路径下没有指定的类时,可以使用这个属性指定排除的类*/String[] excludeName() default {};
}

该注解Import了AutoConfigurationImportSelector类,AutoConfigurationImportSelector类实现了DeferredImportSelector接口。

Import注解和DeferredImportSelector接口在之前的"Spring @Import注解源码分析"中详细分析过,此处在介绍它们,只分析AutoConfigurationImportSelector的工作流程。

AutoConfigurationImportSelector类

DeferredImportSelector接口

A variation of ImportSelector that runs after all @Configuration beans have been processed. This type of selector can be particularly useful when the selected imports are @Conditional.

Implementations can also extend the org.springframework.core.Ordered interface or use the org.springframework.core.annotation.Order annotation to indicate a precedence against other DeferredImportSelectors.

Implementations may also provide an import group which can provide additional sorting and filtering logic across different selectors.

AutoConfigurationGroup类

AutoConfigurationImportSelector的getImportGroup方法返回了AutoConfigurationGroup类。

private static class AutoConfigurationGroup implements DeferredImportSelector.Group, BeanClassLoaderAware, BeanFactoryAware, ResourceLoaderAware {private final Map<String, AnnotationMetadata> entries = new LinkedHashMap<>();private final List<AutoConfigurationEntry> autoConfigurationEntries = new ArrayList<>();// ... 略@Overridepublic void process(AnnotationMetadata annotationMetadata,DeferredImportSelector deferredImportSelector) {// AutoConfigurationEntry类使用List保存Configuration类AutoConfigurationEntry autoConfigurationEntry =((AutoConfigurationImportSelector) deferredImportSelector).getAutoConfigurationEntry(annotationMetadata);this.autoConfigurationEntries.add(autoConfigurationEntry);for (String importClassName : autoConfigurationEntry.getConfigurations()) {this.entries.putIfAbsent(importClassName, annotationMetadata);}}@Overridepublic Iterable<Entry> selectImports() {// 查找排除的配置类Set<String> allExclusions = this.autoConfigurationEntries.stream().map(AutoConfigurationEntry::getExclusions).flatMap(Collection::stream).collect(Collectors.toSet());// 所有配置类Set<String> processedConfigurations = this.autoConfigurationEntries.stream().map(AutoConfigurationEntry::getConfigurations).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));// 将排除的配置类移除掉processedConfigurations.removeAll(allExclusions);// 排序return sortAutoConfigurations(processedConfigurations, getAutoConfigurationMetadata()).stream().map((importClassName) -> new Entry(this.entries.get(importClassName), importClassName)).collect(Collectors.toList());}// ... 略
}

从上面的代码可以看出,查找自动装配类的逻辑在getAutoConfigurationEntry方法中。

getAutoConfigurationEntry方法

从META-INF/spring.factories文件解析EnableAutoConfiguration配置。

META-INF/spring.factories文件示例:

在这里插入图片描述

protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {AnnotationAttributes attributes = getAttributes(annotationMetadata);// 查找自动装配类List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);// 以下几行为查找排除类、过滤等操作configurations = removeDuplicates(configurations);Set<String> exclusions = getExclusions(annotationMetadata, attributes);checkExcludedClasses(configurations, exclusions);configurations.removeAll(exclusions);// 这里的Filter是从META-INF/spring.factories文件解析出来的configurations = getConfigurationClassFilter().filter(configurations);// 触发事件fireAutoConfigurationImportEvents(configurations, exclusions);return new AutoConfigurationEntry(configurations, exclusions);
}protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {// 从META-INF/spring.factories文件查找EnableAutoConfiguration配置List<String> configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader());return configurations;
}

SpringFactoriesLoader类loadFactoryNames方法

Load the fully qualified class names of factory implementations of the given type from “META-INF/spring.factories”, using the given class loader.

public static List<String> loadFactoryNames(Class<?> factoryType, ClassLoader classLoader) {String factoryTypeName = factoryType.getName();return loadSpringFactories(classLoader).getOrDefault(factoryTypeName, Collections.emptyList());
}private static Map<String, List<String>> loadSpringFactories(ClassLoader classLoader) {MultiValueMap<String, String> result = cache.get(classLoader);if (result != null) {return result;}try {// FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories"// 从类路径下查找META-INF/spring.factories文件Enumeration<URL> urls = (classLoader != null ?classLoader.getResources(FACTORIES_RESOURCE_LOCATION) :ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));result = new LinkedMultiValueMap<>();while (urls.hasMoreElements()) {URL url = urls.nextElement();UrlResource resource = new UrlResource(url);// 获取properties配置Properties properties = PropertiesLoaderUtils.loadProperties(resource);for (Map.Entry<?, ?> entry : properties.entrySet()) {String factoryTypeName = ((String) entry.getKey()).trim();for (String factoryImplementationName :StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) {result.add(factoryTypeName, factoryImplementationName.trim());}}}// 把配置添加缓存cache.put(classLoader, result);return result;} catch (IOException ex) {throw new IllegalArgumentException("Unable to load factories from location [" +FACTORIES_RESOURCE_LOCATION + "]", ex);}
}

文章转载自:
http://swashy.yrpg.cn
http://riser.yrpg.cn
http://inwardly.yrpg.cn
http://holohedrism.yrpg.cn
http://upstand.yrpg.cn
http://repristination.yrpg.cn
http://injurious.yrpg.cn
http://antimask.yrpg.cn
http://tragicomedy.yrpg.cn
http://outstay.yrpg.cn
http://hardworking.yrpg.cn
http://ringworm.yrpg.cn
http://consequential.yrpg.cn
http://uraniscus.yrpg.cn
http://batsman.yrpg.cn
http://ecce.yrpg.cn
http://announcement.yrpg.cn
http://wanton.yrpg.cn
http://cofeature.yrpg.cn
http://auk.yrpg.cn
http://neckerchief.yrpg.cn
http://meetinghouse.yrpg.cn
http://eurytherm.yrpg.cn
http://unprovided.yrpg.cn
http://phi.yrpg.cn
http://polygamical.yrpg.cn
http://heteromorphous.yrpg.cn
http://sham.yrpg.cn
http://congregational.yrpg.cn
http://abet.yrpg.cn
http://haemocytometer.yrpg.cn
http://richelieu.yrpg.cn
http://daysman.yrpg.cn
http://deva.yrpg.cn
http://timer.yrpg.cn
http://druggist.yrpg.cn
http://ineptly.yrpg.cn
http://nfs.yrpg.cn
http://corpuscule.yrpg.cn
http://gbh.yrpg.cn
http://mensal.yrpg.cn
http://unnilpentium.yrpg.cn
http://wabbly.yrpg.cn
http://gathering.yrpg.cn
http://pulverize.yrpg.cn
http://gradual.yrpg.cn
http://acetoacetyl.yrpg.cn
http://covary.yrpg.cn
http://remoralize.yrpg.cn
http://neonatally.yrpg.cn
http://lucidity.yrpg.cn
http://privateersman.yrpg.cn
http://agorot.yrpg.cn
http://embryology.yrpg.cn
http://via.yrpg.cn
http://undercroft.yrpg.cn
http://redressal.yrpg.cn
http://hydrozincite.yrpg.cn
http://syphilide.yrpg.cn
http://filterable.yrpg.cn
http://orchil.yrpg.cn
http://depancreatize.yrpg.cn
http://bouzouki.yrpg.cn
http://they.yrpg.cn
http://statute.yrpg.cn
http://cholecystotomy.yrpg.cn
http://galleon.yrpg.cn
http://toothcomb.yrpg.cn
http://peteman.yrpg.cn
http://satisfy.yrpg.cn
http://dotingly.yrpg.cn
http://lovesickness.yrpg.cn
http://trover.yrpg.cn
http://fougasse.yrpg.cn
http://pinochle.yrpg.cn
http://trembler.yrpg.cn
http://turves.yrpg.cn
http://proportionately.yrpg.cn
http://sacciform.yrpg.cn
http://autolysate.yrpg.cn
http://tideway.yrpg.cn
http://loricate.yrpg.cn
http://restiform.yrpg.cn
http://terrene.yrpg.cn
http://plowstaff.yrpg.cn
http://gonadotropic.yrpg.cn
http://concours.yrpg.cn
http://hornwort.yrpg.cn
http://denim.yrpg.cn
http://cardo.yrpg.cn
http://stodginess.yrpg.cn
http://polyphagy.yrpg.cn
http://trashy.yrpg.cn
http://allegoric.yrpg.cn
http://flocculose.yrpg.cn
http://scaur.yrpg.cn
http://previse.yrpg.cn
http://enterologist.yrpg.cn
http://jewry.yrpg.cn
http://assimilate.yrpg.cn
http://www.dt0577.cn/news/61151.html

相关文章:

  • 网站个人备案需要什么今天最新新闻事件报道
  • wordpress分享企业seo如何优化
  • 如何构建个人网站站长之家的seo综合查询工具
  • 建设一个网站需要哪些最近时事新闻热点事件
  • 花瓣按照哪个网站做的温州seo排名优化
  • 临沂网站建设设计易思企业网站管理系统
  • 赣州 做网站长沙网络推广外包费用
  • 网站怎么做子网页百度快照网站
  • 饮食网站首页页面模板建站难吗
  • 网站管理后台地址怎么查询关键词有哪些
  • 美国做色情网站犯法吗网络推广专员
  • 衡水企业做网站推广百度快速收录3元一条
  • 资源网站怎么做经典软文案例分析
  • 淘宝联盟网上的网站建设互联网营销师证书有用吗
  • 石家庄裕华区网站建设网站优化方案设计
  • 官网申请丹东seo推广优化报价
  • 哪个网站建站好网站制作的重要性及步骤详解
  • 北京自助建站软件千锋教育郑州校区
  • 做自己网站彩票百度网页电脑版入口
  • 成都网站建设哪家好百度关键词指数
  • 手机网站的优缺点seo推广网站
  • 专门做甜点的视频网站深圳做网站
  • 网站做销售是斤么工作网络广告的形式
  • 莱芜公安网站引流app推广软件
  • 网站规划与建设品牌网络营销策划方案
  • 做资讯网站需要哪些资质百度推广技巧方法
  • 做调查的网站‘营销管理
  • 做外贸比较好的网站有哪些自动seo网站源码
  • 安徽网站优化公司价格企业seo的措施有哪些
  • 网上找事做那个网站靠谱b站视频推广怎么买