Spring Boot切换不同容器

使用Spring Boot切换不同容器(Tomcat、Jetty、Undertow)的配置,分别列举application.properties、application.yml、pom.xml 的配置示例。

1、application.properties配置示例

1、切换到Tomcat容器:properties
spring.main.web-application-type=SERVLET
server.servlet.container=org.apache.catalina.startup.Tomcat


2、切换到Jetty容器:properties
spring.main.web-application-type=SERVLET
server.servlet.container=org.eclipse.jetty.server.Server


3、切换到Undertow容器:properties
spring.main.web-application-type=SERVLET
server.servlet.container=io.undertow.servlet.core.DeploymentManagerImpl

2、application.yml配置示例

1、切换到Tomcat容器:
spring:
  main:
    web-application-type: SERVLET
  servlet:
    container: org.apache.catalina.startup.Tomcat

2、切换到Jetty容器:
spring:
  main:
    web-application-type: SERVLET
  servlet:
    container: org.eclipse.jetty.server.Server

3、切换到Undertow容器:
spring:
  main:
    web-application-type: SERVLET
  servlet:
    container: io.undertow.servlet.core.DeploymentManagerImpl

3、pom.xml配置示例

1、切换到Tomcat容器

<properties>
    <java.version>1.8</java.version>
    <tomcat.version>9.0.41</tomcat.version>
</properties>

<dependencies>
    <!-- Tomcat容器 -->
    <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.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>${tomcat.version}</version>
    </dependency>
</dependencies>

2、切换到Jetty容器

<properties>
    <java.version>1.8</java.version>
    <jetty.version>9.4.40.v20210413</jetty.version>
</properties>

<dependencies>
    <!-- Jetty容器 -->
    <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.eclipse.jetty</groupId>
        <artifactId>jetty-server</artifactId>
        <version>${jetty.version}</version>
    </dependency>
</dependencies>

3、切换到Undertow容器

<properties>
    <java.version>1.8</java.version>
    <undertow.version>2.2.5.Final</undertow.version>
</properties>

<dependencies>
    <!-- Undertow容器 -->
    <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>io.undertow</groupId>
        <artifactId>undertow-core</artifactId>
        <version>${undertow.version}</version>
    </dependency>
</dependencies>

请根据实际需求选择适合的容器,并将相应的配置添加到Spring Boot应用程序的配置文件(application.properties或application.yml)或pom.xml中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值