• 基础springboot扫描讲解


    基础springboot扫描讲解

    springboot就是一个第三方提供的一个自动装配框架。可以快速的帮助开发,构建架构,Tomcat内置运行,打包完成后为一个jar,java -jar springbootXXXXXX.jar 就可以运行。

    springboot自动装配的原理,创建一个main入口,在类上注解@SpringBootApplication,这就完成了springboot的基本配置,前提是pom.xml配置好依赖

    在这里插入图片描述

    @SpringBootApplication是如何进行自动装配?
    点击@SpringBootApplication
    在这里插入图片描述
    进入@SpringBootApplication注解,我们可以看到有几个@注解:
    @Target,@Retention,@Documented,@Inherited这几个注解不多说
    主要讲:@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan

    点击进入@SpringBootConfiguration
    在这里插入图片描述
    看到什么,@configuration,说明什么,说明@SpringBootApplication本身就是一个ioc容器配置类,可以进行自动装配,在写代码时配置的@Controller,@Service,@Component,@Repository自动扫描配置到ioc容器中,供springboot调用。

    进入@EnableAutoConfiguration
    在这里插入图片描述
    @AutoConfigurationPackage:自动配置包,扫描指定的package包
    @Import:导入.class,将类导入ioc容器
    @Import导入了一个AutoConfigurationImportSelector.class,AutoConfigurationImportSelector有一个方法selectImports(),这个方法是返回的数组中是需要自动装配的全限定类名, 底层会根据数组中的全限定类名将这些类进行注入.
    在这里插入图片描述
    selectImports下面有一个方法List configurations = getCandidateConfigurations(annotationMetadata,
    attributes);进入getCandidateConfigurations,可以看它去找配置文件
    在这里插入图片描述
    表面了在orgspringframeworkootspring-boot-autoconfigure.0.2.RELEASEspring-boot-autoconfigure-2.0.2.RELEASE.jar ,META-INF/spring.factories有一个配置文件
    在这里插入图片描述
    springboot就扫描这个配置文件下的包名,进行自动装配,注入ioc。

  • 相关阅读:
    心里明白,面上糊涂
    【SpringBoot】常用的的各种注解(二):Controller层相关注解
    Flutter-自定义可展开文本控件
    KMP算法小结
    node.js学习笔记 10包管理器
    新人学习笔记之(注释和关键字)
    Java内存模型(JMM)
    第一章 动态网页基础 ① 笔记
    Docker踩坑,又涨知识了
    【源码】数据可视化:基于 Echarts + Java SpringBoot 动态实时大屏范例 - 监管系统
  • 原文地址:https://blog.csdn.net/m0_54849806/article/details/126565585