Spring Boot Server容器配置

mac2024-04-08  45

 

 

参数配置容器

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也可以使用下面对应的特定的容器工厂类。

 

// Jetty

org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory

 

// Tomcat

org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory

 

// Undertow

org.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>

 

推荐阅读


 

Spring Cloud是什么,和Dubbo对比呢?

SpringCloud注册中心高可用搭建

SpringCloud Eureka自我保护机制

SpringCloud服务安全连接

SpringCloud配置中心高可用搭建

SpringCloud配置中心客户端读取配置

SpringCloud动态刷新配置信息

SpringCloud配置中心内容加密

 

看完有没有收获?

分享到朋友圈给更多的人吧。

 


 

 

  Java技术栈  

微信公众号:「Javastack」

 

分享Java干货,高并发编程,热门技术教程,微服务及分布式技术,架构设计,区块链技术,人工智能,大数据,Java面试题,以及前沿热门资讯等。

 

 ▼长按二维码关注我们↓↓↓

 

原文地址:https://mp.weixin.qq.com/s/aEghlvBHE9rpfsAjiq1Kfw 

最新回复(0)