我剛剛初始化了一個新的 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基于依賴關系的,但我錯了嗎?
1 回答

瀟湘沐
TA貢獻1816條經驗 獲得超6個贊
您需要從構建中排除 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'
}
添加回答
舉報
0/150
提交
取消