Springboot detailed introduction

SpringBoot has three built-in Servlet containers, Tomcat, Jetty, and undertow. We only need a Java running environment to run SpringBoot projects, and SpringBoot projects can be packaged into a jar package.

And SpringBoot uses JavaConfig to configure Spring and provides a large number of annotations, which greatly improves work efficiency. For example, @Configuration is combined with @bean annotations, class scanning is completed based on @Configuration, and return values are injected into IOC based on @bean annotations. container,and integrates commonly used dependency groups and merges them into one dependency, so that it can be added to the project’s Maven or Gradle build at once. It is make springboot to easy to use.


I am used to using the application.yaml configuration file

YAML file format is a JSON superset file format supported by Spring Boot. It is data-centered and is more advanced than properties, xml, etc. Suitable for configuration files.

Compared with xml, yml lacks some structured code, making the data more direct and clear at a glance. And More concise than properties files,And I like the application.yml file uses the “key: (space) value” format to configure properties, and uses indentation to control hierarchical relationships.

Spring Boot Source Code Analysis


1.spring-boot-starter-parent

The unified version parent project for dependency management in Spring Boot projects.

In the underlying source files, the Java version of the project is defined, as well as the encoding format for the project’s source code and compiled files, and the version for Maven packaging and compilation.

Next, resource find is performed in the build section.

Then, from spring-boot-starter-parent, the parent dependency spring-boot-dependencies is found. Inside it, various version declarations are defined. Through these declarations, some dependencies do not need to specify version numbers, while some third-party JARs that are not imported still need to declare their version numbers.

2.spring-boot-starter-web

Manages the packaging and dependency of JARs for Spring Boot projects.

In the parent dependency spring-boot-starters package of spring-boot-starter-web, various dependency package imports can be found under its dependencies tag.

3.Embedded Tomcat Principle

Spring Boot supports Tomcat, Jetty, and Undertow as underlying containers by default. Spring Boot defaults to using Tomcat, so once the spring-boot-starter-web module is imported, Tomcat is used as the default container.

When the program enters the getAutoConfigurationEntry method in the AutoConfigurationImportSelector class, it loads the relevant configuration classes from the spring.factories configuration files under the WEB-INF directories of various modules. It obtains the ServletWebServerFactoryAutoConfiguration auto-configuration class, which is the Tomcat auto-configuration.

The getWebServer method in the EmbeddedTomcat class imported by @Import will create and start the embedded Tomcat once it is triggered. This method is inside the TomcatServletWebServerFactory factory class.

In a Spring Boot project, annotations like @RequestMapping can be used directly. In previous projects, besides importing packages, a front controller org.springframework.web.servlet.DispatcherServlet needed to be configured in web.xml. Spring Boot achieves the same effect through auto-configuration. After the injection into the IOC container, the most important step is to register the DispatcherServlet in the servletContext, which is the servlet container.

You can refer to my next article for specific content

No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
:D
Emoji
picure
black!
Previous
Next