- Learning Spring Boot 2.0(Second Edition)
- Greg L. Turnquist
- 247字
- 2021-07-02 15:18:08
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.
推薦閱讀
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- Learning ASP.NET Core 2.0
- The React Workshop
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Xamarin.Forms Projects
- TypeScript項目開發實戰
- Android程序設計基礎
- Unity 2D Game Development Cookbook
- 用案例學Java Web整合開發
- Web性能實戰
- Apache Camel Developer's Cookbook
- Kotlin極簡教程
- ActionScript 3.0從入門到精通(視頻實戰版)
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- 進入IT企業必讀的324個Java面試題