1. Basic introduction
WebServer supported by SpringBoot: Tomcat, Jetty, or Undertow


##SpringBoot application When starting a web application. web scene package - import tomcat
Supports the configuration and switching of Tomcat (can also be Jetty, Undertow)
2. Built-in Tomcat configuration
1.Through application. yml completed configuration
server: #Configure port
port: 9999
#Configure tomcat
tomcat:
threads:
#Indicates the maximum of worker threads (the bank has 10 counters, each counter handles 200 requests 10*200=maximum number of connections), the default is 200
max: 10
#The default minimum worker thread is 10
min- spare: 5
#The thread started by tomcat reaches the maximum value, and the number of queued requests is accepted, the default is 100
accept-count: 200
#Maximum number of connections, number of concurrency
max-connections: 2000
#The timeout for establishing a connection, the default is 20 seconds, in milliseconds
connection-timeout: 10000
2. Configure Tomcat through classes
Configure through classes Tomcat (Note: The configuration file can be configured more fully.)
Log out application.yml to configure tomcat and complete the test
1 2 3 4 5 6 7 8 9 10 |
@Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory server) {
server.setPort(10000);
}
}
|
Copy after login
3. Switch WebServer
Demonstrate how to switch to Undertow
1. Exclude the embedded tomcat dependency
1 2 3 4 5 6 7 8 9 10 | <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
|
Copy after login
2.Introduce the undertow dependency
1 2 3 4 5 | <!-- 引入 undertow -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
|
Copy after login
3. Note: Because the tomcat dependency is removed, the project is used If you go to tomcat related classes/interfaces, an error will be reported. Just log out/delete this part of the code, run the project, and complete the test
The above is the detailed content of How to configure and switch Tomcat with SpringBoot. For more information, please follow other related articles on the PHP Chinese website!