By default, Spring boot uses the Tomcat container. Sometimes, you might want to use a jetty container instead of Tomcat. Spring boot makes it easy to configure jetty containers by providing jetty starter. Add Spring-boot-starter-jetty Dependencies
Add a configuration if you are using MAVEN.
<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>
If you use Gradle, add the following configuration.
Configurations {
compile.exclude module: "Spring-boot-starter-tomcat"
}
dependencies {
compile (" Org.springframework.boot:spring-boot-starter-web:2.0.0.build-snapshot ")
compile (" Org.springframework.boot: Spring-boot-starter-jetty:2.0.0.build-snapshot ")
}
Configure Jetty
Add a configuration to the application.properties to overwrite the jetty default configuration.
server.port=8080
server.servlet.context-path=/home
### #Jetty specific properties########
Server.jetty.acceptors= # acceptor Number of Threads
server.jetty.max-http-post-size=0 # Put or Post method maximum bytes
Server.jetty.selectors= # selector Number of threads
In addition, the Jettyembeddedservletcontainerfactory class can be configured using code.
@Bean public jettyembeddedservletcontainerfactory jettyembeddedservletcontainerfactory () {
Jettyembeddedservletcontainerfactory Jettycontainer = new Jettyembeddedservletcontainerfactory ();
Jettycontainer.setport (9000);
Jettycontainer.setcontextpath ("/home");
return jettycontainer; }