Springboot启动原理分析
1.Springboot启动原理分析
1.1 继承spring-boot-starter-parent,就相应的继承了一些版本控制的东西
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
点击spring-boot-starter-parent,发现它又继承spring-boot-dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.5.0</version>
</parent>
点击spring-boot-dependencies,里面有maven 依赖的相应版本依赖引入
1.2 看一下spring-boot-starter-web帮我们做了什么事
里面引入了springmvc,tomcat等等东西
点一下spring-boot-starter-json看一下
点一下看看spring-boot-starter-tomcat看一下,里面嵌套了tomcat的相关东西
2.Springboot的自动配置
1.点击注解@SpringBootApplication
2.再点击注解@SpringBootConfiguration,结果发现其实就是一个配置类,也就是说SpringBootApplication本身就具备一个配置类configuration的功能
3.点击1出来的截图上的注解@EnableAutoConfiguration,这是springboot自动配置的核心注解
4.componetScan组件扫描,约定了这个启动类所在的包,及其所有子包都进行扫描
其实@SpringBootApplication注解是可以代替3个注解的作用
Configuration,ComponetScan,EnableAutoConfiguration的作用
3.Springboot的核心注解EnableAutoConfiguration
是否可以自动配置
点击AutoConfigurationImportSelector
点击进去,找到最核心的getCandidateConfigurations
当前的类所在的jar包的META-INF/spring.fact
org.springframework.boot.autoconfigure
找到spring.factories
举个例子找servlet关键字里的ServletWebServerFactoryAutoConfiguration,发现里面有一个EnableConfigurationProperties(ServerProperties.class)
发现里面都是配置
具体默认的值在哪呢
是在和META-INF/spring-configuration-metadata.json里
{
"name": "server.port",
"type": "java.lang.Integer",
"description": "Server HTTP port.",
"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties",
"defaultValue": 8080
}
4.autoconfigure
覆盖默认配置
application.properties
server.port=8081
server.servlet.context-path=/demo
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
2020-10-29 Redis面试题
2020-10-29 Count(1),Count(*),Count(column)区别
2020-10-29 Mysql索引创建及删除
2020-10-29 springboot 非端口模式启动
2020-10-29 sql批量插入缓慢