WebServer supported by SpringBoot: Tomcat, Jetty, or Undertow
##SpringBoot application When starting a web application. web scene package - import tomcatSupports the configuration and switching of Tomcat (can also be Jetty, Undertow)2. Built-in Tomcat configuration1.Through application. yml completed configurationserver:2. Configure Tomcat through classesConfigure through classes Tomcat (Note: The configuration file can be configured more fully.)Log out application.yml to configure tomcat and complete the test#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
/** * 通过类来配置Tomcat */ @Component public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { @Override public void customize(ConfigurableServletWebServerFactory server) { server.setPort(10000); //我们设置了server的端口为10000 } }
<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>
<!-- 引入 undertow --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
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!