首页 > 解决方案 > 如何在 Spring Boot 应用程序中更改服务器?

问题描述

我的项目要求是使用除 tomcat 之外的另一台服务器?我们如何从 Spring Boot 应用程序中更改嵌入式服务器?

标签: javaspringspring-boottomcat

解决方案


您将需要更新pom.xml,添加对spring-boot-starter-jetty. 此外,您需要exclude默认添加spring-boot-starter-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.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

在毕业典礼上,

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
}
 
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-jetty")
}

推荐阅读