When you first got into Spring Boot, most of you should be as curious as I am:
Why does Spring Boot not require additional Tomcat installation?
Why on earth? Let’s begin today’s journey with curiosity.
Open the ToBeBetterJavaer project we built in the previous section and go to the pom.xml file, where you can see a parent property as follows:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> The < version > 2.6.1 < / version > < relativePath / > <! -- lookup parent from repository --> </parent>Copy the code
What does that mean?
Our current Spring Boot project relies on the spring-boot-starter-parent project. It has a taste of Java’s extends.
How to view the contents of the spring-boot-starter-parent-pom file?
If you are not sure where your Maven local repository is, run the MVN help:effective- Settings command from the terminal.
The spring-boot-starter-parent-pom file can be locked based on the parent groupId, artifactId, or version.
When opened with a text editor, you can see roughly the following:
- JDK version 1.8 is defined
- The default encoding for the project is UTF-8
- Maven’s compilation environment
- And parent spring-boot-dependencies
Following suit, we find the spring-boot-dependencies. Pom file the same way. You can see that there are a number of properties and dependencies defined, almost 2800 lines.
There are message queue dependencies, Commons toolkit dependencies, database link dependencies, HTTP link dependencies, Spring family dependencies, Web server dependencies, and so on.
This is the version management center on which the Spring Boot project depends.
By default, the version manager is configured with all the versions of the base environment required by the project, which will change as the Spring Boot version is upgraded. This means that the developer does not need to care about the trivial dependencies of the version, but just leaves it to Spring Boot.
Spring Boot will help us choose the most stable new version, which embodies the spirit of the Spring Boot project: “Convention is better than configuration.” You can configure it if you want, but you don’t have to, just follow the rules.
With this in mind, let’s move on to the POm. XML file, which has a spring-boot-starter-Web dependency. This time, hold down the Ctrl key (macOS is Command) and click the left mouse button to jump to the spring-boot-starter-web.pom source file.
Part of the source code is as follows:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.6.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> < artifactId > spring - the boot - starter - json < / artifactId > < version > 2.6.1 < / version > < scope > compile < / scope > < / dependency > <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>2.6.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org. springFramework </groupId> <artifactId> Spring -web</artifactId> <version>5.3.13</version> <scope>compile</scope> </dependency> <dependency> < the groupId > org. Springframework < / groupId > < artifactId > spring - webmvc < / artifactId > < version > 5.3.13 < / version > <scope>compile</scope> </dependency>Copy the code
Spring-web provides core HTTP integration, including some handy servlet filters, Spring HTTP calls, and infrastructures and technologies for integrating with other Web frameworks (Hessian, Burlap).
Spring-webmvc is an implementation of Spring MVC. Spring-web MVC relies on spring-Web, so including it indirectly adds spring-Web without having to show that it adds spring-Web.
Take a look at the poM file for spring-boot-starter-Tomcat:
<? The XML version = "1.0" encoding = "utf-8"? > < project xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" XMLNS = "http://maven.apache.org/POM/4.0.0" XMLNS: xsi = "http://www.w3.org/2001/XMLSchema-instance" > < modelVersion > 4.0.0 < / modelVersion > < groupId > org. Springframework. Boot < / groupId > < artifactId > spring - the boot - starter - tomcat < / artifactId > < version > 2.6.1 < / version > < name > spring - the boot - starter - tomcat < / name > <dependencies> <dependency> <groupId>jakarta.annotation</groupId> <artifactId>jakarta.annotation-api</artifactId> <version>1.3.5</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId> Tomcat-embed -core</artifactId> <version>9.0.55</version> <scope>compile</scope> <exclusions> < Exclusion > <artifactId>tomcat-annotations-api</artifactId> <groupId>org.apache.tomcat</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-el</artifactId> <version>9.0.55</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> < artifactId > tomcat embed - websocket < / artifactId > < version > 9.0.55 < / version > the < scope > compile < / scope > < exclusions > <exclusion> <artifactId>tomcat-annotations-api</artifactId> <groupId>org.apache.tomcat</groupId> </exclusion> </exclusions> </dependency> </dependencies> </project>Copy the code
The default startup container for SpringBoot is Tomcat. The core components of Tomcat Jakarta. Annotation, tomcat-Embed -core, tomcat-Annotations – API, org.apache.tomcat.embed are all introduced through Maven.
Core is 9.0.55, Tomcat 9.0.x is 9.0.56, which is a higher version.
Anyway, download 9.0.56 SRC and see if it’s the same.
By contrast, Spring Boot introduces a leaner, more or less identical Tomcat, which is the root reason why Spring Boot does not require an additional Tomcat installation.
Spring Boot’s starter has already done that for us. This is also an important reason for the popularity of Spring Boot, which saves time for developers to configure, and focuses more on the realization of business logic and optimization of performance. As for those complicated configurations, it is ok to give Spring Boot the big butler. As long as there is no problem with good things, there is no need for special customization, it is right to use.
This post has been adapted to GitHub’s 1.0 K + Star open-source column, “The Path to Java Programmer Advancement”. This column is humorous, easy to understand, and extremely friendly and comfortable for Java enthusiasts 😄, The content includes but is not limited to Java foundation, Java Collection framework, Java IO, Java concurrent programming, Java virtual machine, Java enterprise development (Git, SSM, Spring Boot) and other core knowledge points.
Star the repository to become a better Java programmer. You can click the link below to jump to star and witness this exciting moment.
Github.com/itwanger/to…
This column is still listed in GitHub Trending (daily list of Java), which makes the second brother finally feel the happiness of topping the list!
Nothing keeps me here but purpose, and though there are roses by the shore, and trees by the shore, and still harbours, I am not tied.