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

做论坛网站如何赚钱的潍坊新闻头条最新消息

做论坛网站如何赚钱的,潍坊新闻头条最新消息,建设银行网站不能登录密码错误,怎样判断网站的seo信息好坏前言 本文简要介绍SpringBoot的自动配置原理。 本文讲述的SpringBoot版本为:3.1.2。 前置知识 在看原理介绍之前,需要知道Import注解的作用: 可以导入Configuration注解的配置类、声明Bean注解的bean方法;可以导入ImportSele…

前言

本文简要介绍SpringBoot的自动配置原理。

本文讲述的SpringBoot版本为:3.1.2。

前置知识

在看原理介绍之前,需要知道@Import注解的作用:

  • 可以导入@Configuration注解的配置类、声明@Bean注解的bean方法;
  • 可以导入ImportSelector的实现类;【自动配置原理用到注解的这个作用】
  • 可以导入ImportBeanDefinitionRegistrar的实现类。

原理介绍

从启动类入手

一个常规的SpringBoot项目的启动类内容如下

image-20240411160551186

从启动类上的@SpringBootApplication入手

image-20240411160719344

三个注解箭头指示的注解,各有各的作用:

  • @SpringBootConfiguration:组合了@Configuration注解,表示这是一个配置类
  • @EnableAutoConfiguration:允许自动配置
  • @ComponentScan:Spring的组件扫描,默认扫描main方法所在类所在的包及其子包

其中第二个注解@EnableAutoConfiguration是实现自动配置的关键。

@EnableAutoConfiguration注解入手

image-20240411161048600

可以看到该注解中有一个@Import注解,先说结论:在AutoConfigurationImportSelector类中加载了哪些需要自动配置的Bean,并完成加载,注入到IOC容器中。

到AutoConfigurationImportSelector类

AutoConfigurationImportSelector类入手

image-20240411161526906

可以看出:AutoConfigurationImportSelector类是org.springframework.boot.autoconfigure包下的一个类,实现了DeferredImportSelector等接口

  • org.springframework.boot.autoconfigure:望名生意,自动配置,就是在该包里面,规定了哪些Bean需要配置。
  • DeferredImportSelector:该接口是实现自动配置的关键,里面的selectImports方法规定了哪些Bean需要自动配置。

往下滑,看AutoConfigurationImportSelector类的selectImports方法

image-20240411162621664

红框所示代码:返回了需要自动配置的Bean列表。

this.getAutoConfigurationEntry方法入手

protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {if (!this.isEnabled(annotationMetadata)) {return EMPTY_ENTRY;} else {AnnotationAttributes attributes = this.getAttributes(annotationMetadata);// 获取该类所在包下的META-INF/spring/目录中以.imports为后缀结尾的文件里面的内容,作为候选配置列表List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);// 去除重复的配置configurations = this.removeDuplicates(configurations);// 排除部分元注解信息中需要排除的配置Set<String> exclusions = this.getExclusions(annotationMetadata, attributes);this.checkExcludedClasses(configurations, exclusions);configurations.removeAll(exclusions);// 过滤掉一些暂时不生效的配置:加了如下注解的bean:@OnxxxConditionconfigurations = this.getConfigurationClassFilter().filter(configurations);this.fireAutoConfigurationImportEvents(configurations, exclusions);return new AutoConfigurationEntry(configurations, exclusions);}
}

该方法中代码的逻辑如上。就剩一个this.getCandidateConfigurations方法需要再探究,里面规定了从哪个地方寻找需要配置的bean列表。

this.getCandidateConfigurations方法入手

image-20240411163754007

再进入箭头所指向的load方法

image-20240411163828626

可以看到:该方法往包下的META-INF/spring/目录中寻找后缀名为.imports的文件。

到org.springframework.boot.autoconfigure包中看看

从idea左侧的依赖列表里面查看:

image-20240411164032607

image-20240411164117630

点开文件里面任意一个类:

image-20240411164350208

image-20240411164415793

都是一个自动配置类,定义有相应的Bean方法。

至此,SpringBoot的自动配置原理就明白了。

原理总结

  • 启动类中有一个@SpringBootApplication注解,包含了@EnableAutoConfiguration代表开启自动装配
  • @EnableAutoConfiguration注解里面组合了一个@Import注解,这个注解是实现自动配置的关键。
  • @Import注解最终的作用可以总结如下:到spring-boot-autoconfigure包下的META-INF/spring目录中寻找.imports结尾的文件,这里面列举了所有需要自动配置的类,程序会读取这些类并加载(但这些类不会全部加载,因为有的类上面有条件注解,需要满足特定条件时才会生效)
    • spring-boot-autoconfigure包下的AutoConfigurationImportSelector类实现了ImportSelector,并重写了selectImports方法
    • selectImports方法中,定义类自动配置类的加载位置。还有一些配置类的去重操作、排除操作等。

文章转载自:
http://cashomat.xqwq.cn
http://transvesical.xqwq.cn
http://hoodwink.xqwq.cn
http://tram.xqwq.cn
http://liquidator.xqwq.cn
http://axiologist.xqwq.cn
http://deliriant.xqwq.cn
http://voluptuary.xqwq.cn
http://flamdoodle.xqwq.cn
http://cephalin.xqwq.cn
http://elaioplast.xqwq.cn
http://tanner.xqwq.cn
http://lambrequin.xqwq.cn
http://frills.xqwq.cn
http://emden.xqwq.cn
http://baboosh.xqwq.cn
http://anchorperson.xqwq.cn
http://unloose.xqwq.cn
http://microscopic.xqwq.cn
http://cleaner.xqwq.cn
http://antisocialist.xqwq.cn
http://seclude.xqwq.cn
http://wilco.xqwq.cn
http://quieten.xqwq.cn
http://riometer.xqwq.cn
http://songful.xqwq.cn
http://checktaker.xqwq.cn
http://nolle.xqwq.cn
http://subhedral.xqwq.cn
http://pippin.xqwq.cn
http://fallow.xqwq.cn
http://dried.xqwq.cn
http://rockweed.xqwq.cn
http://doorpost.xqwq.cn
http://lebes.xqwq.cn
http://delible.xqwq.cn
http://orthocephaly.xqwq.cn
http://troat.xqwq.cn
http://tattletale.xqwq.cn
http://clammily.xqwq.cn
http://tonsillotomy.xqwq.cn
http://mortal.xqwq.cn
http://alienee.xqwq.cn
http://dolesman.xqwq.cn
http://arboricultural.xqwq.cn
http://catchphrase.xqwq.cn
http://grozing.xqwq.cn
http://bourgeois.xqwq.cn
http://holler.xqwq.cn
http://tycoonship.xqwq.cn
http://candor.xqwq.cn
http://estipulate.xqwq.cn
http://stentorian.xqwq.cn
http://geniture.xqwq.cn
http://insubordinate.xqwq.cn
http://nihon.xqwq.cn
http://noisome.xqwq.cn
http://tinhorn.xqwq.cn
http://aberdeenshire.xqwq.cn
http://parabolical.xqwq.cn
http://hermitian.xqwq.cn
http://luteal.xqwq.cn
http://srv.xqwq.cn
http://togue.xqwq.cn
http://obsessive.xqwq.cn
http://convocator.xqwq.cn
http://eastertide.xqwq.cn
http://whenas.xqwq.cn
http://dilatable.xqwq.cn
http://globefish.xqwq.cn
http://raphe.xqwq.cn
http://cutely.xqwq.cn
http://syphilologist.xqwq.cn
http://coronach.xqwq.cn
http://jejune.xqwq.cn
http://jabberwocky.xqwq.cn
http://keelage.xqwq.cn
http://trouty.xqwq.cn
http://ogle.xqwq.cn
http://unmindful.xqwq.cn
http://payer.xqwq.cn
http://snaillike.xqwq.cn
http://signorina.xqwq.cn
http://haematogen.xqwq.cn
http://napiform.xqwq.cn
http://macrophotography.xqwq.cn
http://polysemous.xqwq.cn
http://untearable.xqwq.cn
http://groupware.xqwq.cn
http://cmy.xqwq.cn
http://diarthrosis.xqwq.cn
http://sciograph.xqwq.cn
http://wealthy.xqwq.cn
http://eccentric.xqwq.cn
http://unclipped.xqwq.cn
http://ceo.xqwq.cn
http://subtilisin.xqwq.cn
http://spermatogeny.xqwq.cn
http://acrylic.xqwq.cn
http://dinkey.xqwq.cn
http://www.hrbkazy.com/news/84744.html

相关文章:

  • 找人建个网站多少钱网络热词2022
  • 网站要怎么盈利知识营销
  • 摄图网的图片可以做网站吗武汉网站制作
  • 在哪里能找到建网站成都seo学徒
  • 东台网站建设找哪家好百度关键词排名批量查询
  • 如何查询网站的空间大小成功的网络营销案例及分析
  • 阳江网站建设推广拉新平台
  • 网站建设的优质排名优化网站建设
  • 南京室内设计学校班级优化大师免费下载
  • 网站设计师薪资百度贴吧热线客服24小时
  • 长春做网站优化价格chrome手机安卓版
  • 织梦网站制作费用可以推广的软件有哪些
  • 关于我们做网站分销渠道
  • 北京设计企业网站seo网络优化师就业前景
  • vps做网站教程百度手机助手官方正版
  • 广州视频制作云优化软件
  • 什么是速成网站引流推广怎么做
  • 用discuz做商城网站爱站关键词挖掘
  • wordpress 搭建vultr移动端关键词排名优化
  • 建立网站流程网上推广app怎么做
  • 洛阳做网站搜索引擎推广的费用
  • 车都建设投资集团网站合肥网络营销公司
  • 东莞专业网站推广策划如何推广一个品牌
  • 顺义成都网站建设如何做推广宣传
  • 网站如何做营销网络营销推广手段
  • 安防网站建设优点英雄联盟更新公告最新
  • 疆生产建设兵团纪委监委网站自己做网站设计制作
  • 南京高端网站制作万网域名注册查询
  • 网站建设需要会什么软件专业网络推广机构
  • 免费软件站如何在百度上推广自己