默认情况下,Spring Boot会使用内置的tomcat容器去运行应用程序,但偶尔我们也会考虑使用Jetty去替代Tomcat;
对于Tomcat和Jetty,Spring Boot分别提供了对应的starter,以便尽可能的简化我们的开发过程;
当我们想使用Jetty的时候,可以参考以下步骤来使用。
我们需要更新pom.xml文件,添加spring-boot-starter-jetty依赖,同时我们需要排除spring-boot-starter-web默认的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>
如果我们的工程是使用Gradle构建的话,可以使用以下方式达到同样的效果:
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") }
重启完成之后,再次查看控制台打印的日志信息,Jetty started,以此可以确定替换jetty成功
原文:https://www.cnblogs.com/-flq/p/10441706.html