在springboot项目中切换servlet容器(tomcat、jetty、Undertow)

在springboot项目中默认使用的容器是tomcat,通过查看pom.xml依赖关系可以查看到(在IDEA的项目的pom文件中按Ctrl + shift + Alt + U)。

Jetty(适合开发长连接的应用)。

Undertow(不支持JSP,但是是非阻塞的,并发性能比较好),添加依赖如下:

通过查看spring-boot-starter的关联关系可以看出我的目前已经改为jetty。

配置文件片段如下:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
          <!--将默认starter的tomcat配置排除--> <exclusion> <artifactId>spring-boot-starter-tomcat</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <!--引入其他的servlet容器--> <dependency> <artifactId>spring-boot-starter-jetty</artifactId> <groupId>org.springframework.boot</groupId> </dependency>

运行后,查看控制台输出的,下图的倒数第二行Jetty started.....,说明配置生效,并且继承了之前在application.properties中的相关配置。

学会这一种,undertow也就会替换了。

 

posted @ 2020-04-12 12:18  。低调ヽ继续  阅读(675)  评论(0编辑  收藏  举报