现在网上大多文章都介绍undertow比tomcat性能好,所以这篇文章给大家介绍下如何把springboot默认的tomcat替换成undertow。
首先修改pom.xml,在
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
这里面添加下排除项,把tomcat排除掉。
<exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions>
最后的样子就是
<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>
然后我们添加上undertow的依赖即可。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
最后,我们把项目打包启动,可以看到undertow启动起来了。
最后再补充一下
1、springboot自动集成了web服务,只是默认使用tomcat而已。
2、不管是tomcat还是undertow,适合自己的才是最好的,不要忙目得去追求网上的性能优化文章。他的使用场景不一定适合你。
还没有评论,来说两句吧...