在 `build.gradle` 中提供了运行时`spring-boot-starter-

我刚刚初始化了一个新的 Spring Boot 应用程序,并且我build.gradle有以下依赖项:


dependencies {

    implementation 'org.springframework.boot:spring-boot-starter-web'

    providedRuntime 'org.springframework.boot:spring-boot-starter-undertow'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'

}

当我运行时./gradlew bootRun,它正在使用 Tomcat。我知道starter-web包括 Tomcat,但没有providedRuntime覆盖它吗?


我如何实际使用 undertow 来运行我的 Spring 控制器?


编辑:


我刚刚意识到我的ServletInitializer.java样子是这样的:


import org.springframework.boot.builder.SpringApplicationBuilder;

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;


public class ServletInitializer extends SpringBootServletInitializer {


    @Override

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

        return application.sources(AccountServiceApplication.class);

    }


}

这告诉我它正在初始化一个 servlet,我假设它是undertow基于依赖关系的,但我错了吗?


收到一只叮咚
浏览 89回答 1
1回答

潇湘沐

您需要从构建中排除 tomcat:dependencies {  implementation ('org.springframework.boot:spring-boot-starter-web') {      exclude module: 'spring-boot-starter-tomcat'}  providedRuntime 'org.springframework.boot:spring-boot-starter-undertow'  testImplementation 'org.springframework.boot:spring-boot-starter-test'}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java