I have just initialised a new Spring Boot application and my build.gradle
has the following dependencies:
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'
}
When I run ./gradlew bootRun
, it is using Tomcat. I understand starter-web
includes Tomcat, but isn't providedRuntime
there to override that?
How do I actually use undertow to run my Spring controllers?
EDIT:
I just realised my ServletInitializer.java
looks like this:
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);
}
}
This tells me it is initialising a servlet, which I assumed is undertow
based on the dependencies, but was I wrong?
You need to exclude tomcat from the build:
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'
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.