Parameter Configuration container

Xx starts with the configuration common to all servlet containers, server.tomcat.xx starts with tomcat specific parameters, and so on.

All parameters binding configuration classes: org. Springframework. Boot. Autoconfigure. Web. ServerProperties

Code configuration container

In addition to using the above parameters to automatically configure the servlet container, you can also do so in code. Can directly implement EmbeddedServletContainerCustomizer this interface, ServerProperties also implements this interface.

@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties
        implements EmbeddedServletContainerCustomizer, EnvironmentAware, Ordered {
...
Copy the code

Of course, Tomcat, Jetty, and Undertow can also use the following specific container factory classes.

// Jetty
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory

// Tomcat
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory

// Undertow
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
Copy the code

Replace the Tomcat

spring-boot-starter-web brings Tomcat with spring-boot-starter-tomcat, but spring-boot-starter-jetty and spring-boot-starter-undertow can be used instead.

Spring-boot-starter-web automatically carries tomcat dependencies, but can also be replaced with Jetty and undertow. Here is an example of jetty being replaced.

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <! -- Exclude the Tomcat dependency --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <! -- Use Jetty instead --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>Copy the code

Recommended reading

Dry goods: 2TB architect four-stage video tutorial

Interview: the most complete Java multithreaded interview questions and answers

Interview: the most comprehensive ali advanced Java interview questions in history

Interview: The most complete Spring interview questions in history

Tutorial: The most complete Spring Boot complete video tutorial

Books: 15 must-read books for advanced Java architects

Tools: Recommended an online creation flow chart, mind mapping software

Share Java dry goods, high concurrency programming, hot technology tutorials, microservices and distributed technology, architecture design, blockchain technology, artificial intelligence, big data, Java interview questions, and cutting-edge hot news.