Spring Boot中如何进行容器配置呢?
下文笔者讲述SpringBoot进行容器配置的方法及示例分享,如下所示
容器参数配置方法
SpringBoot容器配置可以使用 server.xx开头的是所有servlet容器通用的配置 server.tomcat.xx开头的是tomcat特有的参数 其它容器配置方法类似例:
参数配置容器
@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 自动携带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>
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。