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

欧美电影免费网站遂宁网站设计

欧美电影免费网站,遂宁网站设计,网站建设合同要不要交印花税,网站模板 html5自动配置原理 概述原理Spring Boot Starterspring.factories 文件ConditionalOnX 注解配置 Bean配置属性 源码剖析 主页传送门#xff1a;#x1f4c0; 传送 概述 Spring Boot 是一个用于创建独立的、生产级别的 Spring 应用程序的框架。它极大地简化了 Spring 应用程序的开… 自动配置原理 概述原理Spring Boot Starterspring.factories 文件ConditionalOnX 注解配置 Bean配置属性 源码剖析 主页传送门 传送 概述 Spring Boot 是一个用于创建独立的、生产级别的 Spring 应用程序的框架。它极大地简化了 Spring 应用程序的开发过程其中一个关键的功能就是自动配置Auto-Configuration。 自动配置可以根据项目需求自动配置各种服务和组件它可以帮助开发者在不需要显式配置的情况下快速地构建一个运行的应用程序。 自动配置是 Spring Boot 的一个核心特性它通过分析项目的依赖和环境自动地为应用程序配置 Spring 配置文件。这意味着开发者无需手动配置大量的 Spring BeanSpring Boot 会根据环境和项目的依赖来智能地为应用程序创建所需的 Bean。 原理 Spring Boot的自动配置原理基于Java的反射机制和Spring的IoC容器。它通过读取项目中的配置文件如application.properties或application.yml根据配置信息自动创建和配置各种服务。 可以概括为以下几个步骤 Spring Boot Starter Spring Boot 项目通常依赖于所谓的 “Starters”这是一组预定义了常用库的依赖集合。Starters 包含了应用程序所需的所有依赖比如 Web Starter 会包含用于构建 Web 应用程序的所有必要库。 spring.factories 文件 在每个 Starter 的 META-INF/spring.factories 文件中定义了一系列的自动配置类。这些自动配置类会在应用程序启动时被 Spring Boot 自动扫描和加载。 ConditionalOnX 注解 在自动配置类中通常会使用 ConditionalOnX 注解来控制该自动配置是否生效。这个注解会根据特定的条件比如类是否在类路径中、特定的 Bean 是否存在等来决定是否应用这个配置。 配置 Bean 自动配置类会定义一些必要的 Bean并使用 Configuration 注解将它们标记为配置类。这些 Bean 会在 Spring 上下文中被自动注册。 配置属性 自动配置类还可以通过读取 application.properties 或 application.yml 文件中的属性来自定义它们的行为。这样开发者可以根据需要进行定制。 源码剖析 Spring Boot 应用的启动类一般均位于src/main/java根路径下 SpringBootApplication public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);} }SpringBootApplication开启组件扫描和自动配置而SpringApplication.run则负责启动引导应用程序。SpringBootApplication是一个复合Annotation它将三个有用的注解组合在一起 Target(ElementType.TYPE) Retention(RetentionPolicy.RUNTIME) Documented Inherited SpringBootConfiguration EnableAutoConfiguration ComponentScan(excludeFilters {Filter(type FilterType.CUSTOM, classes TypeExcludeFilter.class),Filter(type FilterType.CUSTOM, classes AutoConfigurationExcludeFilter.class) }) public interface SpringBootApplication {// ...省略内容 }SpringBootConfiguration就相当于Configuration它是 Spring 框架的注解标明该类是一个JavaConfig配置类。而ComponentScan启用组件扫描。 EnableAutoConfiguration注解表示开启 Spring Boot 自动配置功能Spring Boot 会根据应用的依赖、自定义的 bean、classpath 下有没有某个类 等等因素来猜测你需要的 bean然后注册到 IOC 容器中。EnableAutoConfiguration是如何推算出需求的首先来看下它的定义 Target(ElementType.TYPE) Retention(RetentionPolicy.RUNTIME) Documented Inherited AutoConfigurationPackage Import(EnableAutoConfigurationImportSelector.class) public interface EnableAutoConfiguration {// ...省略内容 } 重点关注点在Import({AutoConfigurationImportSelector.class}) Import注解用于导入类并将这个类作为一个 bean 的定义注册到容器中这里它将把EnableAutoConfigurationImportSelector作为 bean 注入到容器中而这个类会将所有符合条件的Configuration 配置都加载到容器中查看EnableAutoConfigurationImportSelector代码可以看到 AutoConfigurationImportSelector 实现了DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered 这些接口。核心代码为 public class AutoConfigurationImportSelector implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered {//...public String[] selectImports(AnnotationMetadata annotationMetadata) {if (!this.isEnabled(annotationMetadata)) {return NO_IMPORTS;} else {AutoConfigurationImportSelector.AutoConfigurationEntry autoConfigurationEntry this.getAutoConfigurationEntry(annotationMetadata);return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());}} }再来具体看getAutoConfigurationEntry 方法具体是如何判断哪些是需要导入的。 protected AutoConfigurationImportSelector.AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {if (!this.isEnabled(annotationMetadata)) {return EMPTY_ENTRY;} else {AnnotationAttributes attributes this.getAttributes(annotationMetadata);ListString configurations this.getCandidateConfigurations(annotationMetadata, attributes);configurations this.removeDuplicates(configurations);SetString exclusions this.getExclusions(annotationMetadata, attributes);this.checkExcludedClasses(configurations, exclusions);configurations.removeAll(exclusions);configurations this.getConfigurationClassFilter().filter(configurations);this.fireAutoConfigurationImportEvents(configurations, exclusions);return new AutoConfigurationImportSelector.AutoConfigurationEntry(configurations, exclusions);}}annotationMetadata 参数是一个元数据接口它提供了对注解元数据的访问权限通常用于在运行时检查类上的注解。 getAutoConfigurationEntry(annotationMetadata)方法会根据传入的 annotationMetadata返回一个 AutoConfigurationEntry 对象。 AutoConfigurationEntry 是一个内部类用于封装自动配置项的信息包括该自动配置项的类名、条件Conditions等信息。 通过获取到的 autoConfigurationEntry 对象Spring Boot 就能够知道哪些自动配置类需要被导入从而将它们注册到 Spring 上下文中。 如果喜欢的话欢迎 关注 点赞 评论 收藏 一起讨论你的支持就是我✍️创作的动力
http://www.pierceye.com/news/88737/

相关文章:

  • 做网站 程序员 暴富渭南网站建设服务
  • html 网站开发网站建设的考虑
  • 做教育网站用什么颜色南京手机网站制作
  • 网站建设工作整改报告柳州建设网栗园新居
  • 手机网站开发设计动漫设计师资格证
  • 宝安网站建设制作搬家网站建设公司
  • 怎样建设一个英语网站建设培训网站建设
  • 做网站主页效果图好多公司为啥只做网站 不考虑推广
  • 西城专业网站建设公司哪家好统计网站访客人数
  • 如何做全景网站网络营销策划书范文
  • h5技术网站所见即所得网站管理系统
  • 一站式营销型网站建设服务山西建筑工程集团有限公司
  • 会计证继续教育在哪个网站做免费企业管理培训课程视频
  • 百度广州给做网站公司wordpress输入正确密码无法登陆
  • 种子搜索网站怎么做的佛山网站建设计
  • 模板网站的建设wordpress博客常用插件
  • 南平做网站婚恋网站 备案条件
  • 西宁哪家网络公司做网站广告机
  • dede小视频网站源码专业网站建设制作公司哪家好
  • 做外贸英语网站国外网站做问卷
  • 山西省住房与城乡建设厅网站wordpress如何创建分类
  • 网站运营的具体工作包括哪些2015年做网站行不行
  • 交友类网站功能建设思路企业做网站的困惑
  • 电子商务网站功能页面广东手机网页制作
  • 企业网站建设 招标 评分表南昌微信网站建设
  • 网站开发学习方法网站建站查询
  • 网站建设解析万网域名管理平台登录
  • 深圳网站做的好的公司嘉兴网站搜索排名
  • 梅河口市住房和城乡建设局网站wordpress网站合并
  • 广州五羊建设官方网站的搜索引擎优化