Comments (1)
Spring Boot运行原理
在前面的篇幅中我们重点阐述了为什么Spring Boot可以实现高度地自动化配置(组合注解,条件注解)。那么,接下来我们就结合Spring Boot最核心的组合注解@SpringBootApplication来分析下Spring Boot的项目到底是怎么启动运行的。
@SpringBootApplication注解实际上是一个组合注解,除了对应用开放的@componentscan注解(实现对开发者自定义的应用包扫描)外,其最核心的注解就是注解@EnableAutoConfiguration,该注解表示开启自动配置功能,而在具体的实现上则是通过导入注解@import(EnableAutoConfigurationImportSelector.class)类的实例,在逻辑上实现了对所依赖的核心jar下META-INF/spring.factories文件的扫描,该文件则声明了有哪些自动配置需要被Spring容器加载,从而Spring Boot应用程序就能自动加载Spring核心容器配置,以及其他依赖的项目组件配置,从而最终完成应用的自动初始化,通过这种方法就向开发者屏蔽了启动加载的过程。
如“spring-boot-autoconfigure”核心包中的META-INF/spring.factories文件就是定义了需要加载的Spring Boot项目所依赖的基础配置类,如Spring的容器初始化配置类等。如:
# Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.autoconfigure.BackgroundPreinitializer
.....
而对于大部分第三方需要与Spring Boot集成的框架,或者我们日常开发中需要进行抽象的公共组件而言,得益于这种机制,也可以很容易地定制成开箱即用的各种Starter组件。而使用这些组件的用户,往往只需要将依赖引入就好,不再需要进行任何额外的配置了!
Spring Boot后记
以上就是Spring Boot运行的基本原理了,希望这篇文章能够对你有所帮助!实际上学习Spring Boot进行项目开发关键就是要掌握各种Spring及Spring Boot的各种注解,特别是一些关键核心注解。同样在进行基于Spring Cloud微服务的开发中,也是需要理解Spring Cloud相关组件所提供的各种核心注解,只有这样才能更好的理解框架的原理及使用,而不只是云里雾里地进行各种似懂非懂的Copy开发。
原文链接:https://blog.csdn.net/cowbin2012/article/details/88861160
from tutorial.
Related Issues (20)
- java-thread.md中的一个问题 HOT 4
- finally在Java中的作用
- String 属于基础的数据类型吗?
- Java中操作字符串都有哪些类?它们之间有什么区别?
- 如何将字符串反转?
- 普通类,抽象类,接口有哪些区别?
- 抽象类能使用 final 修饰吗?
- 重载和重写的区别
- 如何实现超大文件的快速上传和下载?
- 比较Thymeleaf, JSP, Freemarker
- 面试题中volatile部分有错
- TODO-List
- 秒杀商城 链接 404了 HOT 1
- mysql.md 一些拼写错误 HOT 1
- README.md 有两个链接404
- log.md 拼写问题
- nginx.md 拼写问题
- Tutorial/plugins/rabbitmq.md 拼写问题
- 算法404了 HOT 2
- 主页的README,go-basic.md链接失效 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tutorial.