How to use Tomcat container to achieve self-starting in springboot
May 12, 2023 am 10:25 AM1. Spring imports beans through annotations, which can be roughly divided into four ways. We mainly talk about the following two implementation methods of Import:
1. Implement Bean loading by implementing the ImportSerlector interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
2. Implement Bean loading by implementing the ImportSerlector interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
2. Springboot will be automatically assembled during startup
We start from spring-boot-autoconfigure-2.0.6.RELEASE I searched for the relevant configuration of Tomcat under .jar and found two automatic assembly classes, each containing three customizers (object-oriented single responsibility principle) and a factory class.
2.1. TomcatWebServerFactoryCustomizer: Customize Tomcat-specific functions common to Servlets and Reactive servers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
2.2. ServletWebServerFactoryCustomizer: WebServerFactoryCustomizer applies the ServerProperties properties to the Tomcat web server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
2.3. ServletWebServerFactoryCustomizer: WebServerFactoryCustomizer applies ServerProperties properties to the Tomcat web server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
3. With TomcatServletWebServerFactory, it is equivalent to having the entrance for Spring loading.
Drive tomcat to start in the IOC container through AbstractApplicationContext#onReFresh(), and then execute other parts of the ioc container. step.
We can observe the entire life cycle of Tomcat loading through breakpoints, as well as the loading process of the three customizers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Note: In this process, we need to understand the life cycle of the Bean. Tomcat's three customizers are loaded in the BeanPostProcessorsRegistrar (Bean post-processor) process;
Constructor method-->Bean post-processorBefore-->InitializingBean-->init-method-->Bean post-processorAfter
1 2 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
The above is the detailed content of How to use Tomcat container to achieve self-starting in springboot. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to allow external network access to tomcat server

How to deploy multiple projects in tomcat

Where is the tomcat installation directory?

Where is the root directory of the tomcat website?

How to check the port number of tomcat

How to check the number of concurrent connections in tomcat

How to run two projects with different port numbers in tomcat
