參數配置容器
server.xx開頭的是所有servlet容器通用的配置,server.tomcat.xx開頭的是tomcat特有的參數,其它類似。
所有參數綁定配置類:org.springframework.boot.autoconfigure.web.ServerProperties
代碼配置容器
除了利用上面的參數來自動配置servlet容器,還可以通過代碼的方式。可以直接實現EmbeddedServletContainerCustomizer這個接口,ServerProperties也是實現這個接口的。
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)public class ServerProperties implements EmbeddedServletContainerCustomizer, EnvironmentAware, Ordered {...
當然如果是Tomcat、Jetty、Undertow也可以使用下面對應的特定的容器工廠類。
// Jettyorg.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory// Tomcatorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory// Undertoworg.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
替換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自動攜帶了tomcat依賴,但也可以替換成jetty和undertow,下面是一個替換jetty的示例。
<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>
推薦閱讀
另外,Java開發者請加入我們的群(274435854),10G電子書,Java乾貨,高併發編程,熱門技術教程,微服務及分佈式技術,架構設計,區塊鏈技術,人工智能,大數據,Java面試題等資源,我們一起學習。
架構之路,頭條精選,每天一篇乾貨,喜歡就收藏+關注吧!
相關推薦
推薦中...