Embedded Web container: Built-in server (Tomcat) in the application, no need to configure the server externally
The SpringBoot project is started and it is found to be a web application. Introducing the web scenario package ----- For example: Tomcat
web application creates a web version of the IOC container ServletWebServerApplicationContext
ServletWebServerApplicationContext when started Looking for ServletWebServerFactory (Servlet's web server factory, used to produce Servlet servers)
ServletWebServerFactory There are many web server factories at the bottom by default
#The bottom layer will be automatically configured, the automatic configuration class ServletWebServerFactoryAutoConfiguration
ServletWebServerFactoryAutoConfiguration imports the ServletWebServerFactoryConfiguration factory configuration class
ServletWebServerFactoryConfiguration.class
Dynamicly determine which web server configuration package is imported into the system
If Importing Tomcat dependencies will automatically place a Tomcat server factory. TomcatServletWebServerFactory creates a Tomcat server factory for us
Tomcat bottom layer supports the following servers
@Override public WebServer getWebServer(ServletContextInitializer... initializers) { if (this.disableMBeanRegistry) { Registry.disableRegistry(); } Tomcat tomcat = new Tomcat(); File baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir("tomcat"); tomcat.setBaseDir(baseDir.getAbsolutePath()); Connector connector = new Connector(this.protocol); connector.setThrowOnFailure(true); tomcat.getService().addConnector(connector); customizeConnector(connector); tomcat.setConnector(connector); tomcat.getHost().setAutoDeploy(false); configureEngine(tomcat.getEngine()); for (Connector additionalConnector : this.additionalTomcatConnectors) { tomcat.getService().addConnector(additionalConnector); } prepareContext(tomcat.getHost(), initializers); return getTomcatWebServer(tomcat); }
Summary: The so-called embedded server is to put our method of manually starting the server into the framework.
Exclude tomcat server and import undertow dependency
<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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
Method One: Modify the configuration file under the server
ServerProperties.class
##server.undertow.accesslog.dir=/tmpMethod 2: Customize ConfigurableServletWebServerFactoryMethod 3: Customize ServletWebServerFactoryCustomizer CustomizerFunction: Bind the value of the configuration file to ServletWebServerFactorySpringBoot Design: Customizer, you can customize XXX rules
The above is the detailed content of How to use SpringBoot embedded web container. For more information, please follow other related articles on the PHP Chinese website!