Home > Java > Java Tutorial > body text

How to configure and switch Tomcat with SpringBoot

王林
Release: 2023-05-27 22:29:27
forward
1474 people have browsed it

1. Basic introduction

WebServer supported by SpringBoot: Tomcat, Jetty, or Undertow

How to configure and switch Tomcat with SpringBoot

How to configure and switch Tomcat with SpringBoot

##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

/**
 * 通过类来配置Tomcat
 */
@Component
public class CustomizationBean implements WebServerFactoryCustomizer {
    @Override
    public void customize(ConfigurableServletWebServerFactory server) {
        server.setPort(10000); //我们设置了server的端口为10000
    }
}
Copy after login

3. Switch WebServer

Demonstrate how to switch to Undertow

1. Exclude the embedded tomcat dependency


   org.springframework.boot
   spring-boot-starter-web
   
      
         org.springframework.boot
         spring-boot-starter-tomcat
      
   
Copy after login

2.Introduce the undertow dependency



   org.springframework.boot
   spring-boot-starter-undertow
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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!