官术网_书友最值得收藏!

Switching from Embedded Netty to Apache Tomcat

By default, Spring Boot is geared up to use embedded Netty (http://netty.io). Why? Because it's one of the most popular solutions for reactive applications. And when it comes to reactive applications, it's critical that the entire stack be reactive.

However, it's possible to switch to another embedded container. We can experiment with using Apache Tomcat and its asynchronous Servlet 3.1 API. All we have to do is to make some tweaks to the dependency settings in build.gradle, as follows:

    compile('org.springframework.boot:spring-boot-starter-webflux') { 
      exclude group: 'org.springframework.boot', 
      module: 'spring-boot-starter-reactor-netty' 
    } 
    compile('org.springframework.boot:spring-boot-starter-tomcat') 

What's happening in the preceding code? This can be explained as follows:

  • spring-boot-starter-webflux excludes spring-boot-starter-reactor-netty, taking it off the classpath
  • spring-boot-starter-tomcat is added to the classpath
  • Spring Boot's TomcatAutoConfiguration kicks in, and configures the container to work using TomcatReactiveWebServerFactory

It's important to point out that there are these other containers available:

  • Jetty
  • Undertow

For the rest of this title, we'll stick with Spring Boot's default, Netty.

It's interesting to refer to these as containers given that they are contained inside our application. It used to be standard practice to install Apache Tomcat (or whatever container we picked) and install the application into it. But Spring Boot has made embedded containers a core feature, inverting this concept of apps inside containers and putting the container inside the app instead. For an entertaining presentation on how this change has swept the Java community, check out Eberhard Wolff's Java Application Servers Are Dead ( http://www.slideshare.net/ewolff/java-application-servers-are-dead) presentation.
主站蜘蛛池模板: 鄂尔多斯市| 永福县| 梧州市| 左权县| 花垣县| 兴和县| 霍林郭勒市| 神农架林区| 洱源县| 玛曲县| 福贡县| 台北县| 濮阳县| 新乡县| 邻水| 东乌珠穆沁旗| 湾仔区| 五原县| 南靖县| 龙里县| 淅川县| 江津市| 皮山县| 斗六市| 车致| 辽阳县| 兴仁县| 县级市| 金坛市| 随州市| 信宜市| 和林格尔县| 霸州市| 大石桥市| 海林市| 永德县| 阿巴嘎旗| 松江区| 尼木县| 北辰区| 城步|