博客
关于我
SpringBoot总结(二)——Spring Boot的自动配置
阅读量:810 次
发布时间:2019-03-25

本文共 699 字,大约阅读时间需要 2 分钟。

从启动类入手,观察其上方标注的 @SpringBootApplication 注解意义重大。这是一个组合注解,其内部组成包括 @SpringBootConfiguration 和 @EnableAutoConfiguration,确保应用具备Spring Boot的标准配置。

细解 @SpringBootApplication 内部机制,首先关注 @SpringBootConfiguration 注解。这一模块性注解为Spring Boot应用设定了主配置类定位规则,即标注该注解的类即为应用的主要Spring配置类。继而,@EnableAutoConfiguration 打开了自动配置功能,这相当于让Spring Boot自自动配置各模块而不需要手动声明。

自动配置的实现精髓在于 @AutoConfigurationPackage。该注解通过 @Import 导入 AutoConfigurationPackages.Registrar 类,其职责是扫描指定包及其子包,收集所有符合条件的组件。系统运行时会读取 META-INF/spring.factories 檔案,解析里面的配置信息,将扫描结果整合到Spring容器。

值得注意的是,通过设置 debug 模式,可以深入探究特定组件的实现原理。特别是如何通过 AutoConfigurationImportSelector 类选择需要导入的配置。

在整体架构中,@SpringBootApplication 标注的主配置类自动成为包扫描范围内的一部分。其所在包及子包中的所有组件都会被引入到Spring容器中,确保配置文件功能齐全。

转载地址:http://wkayk.baihongyu.com/

你可能感兴趣的文章
Nmap扫描教程之Nmap基础知识
查看>>
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>