![](/img/trans.png)
[英]spring initializr: spring-boot-starter vs spring-boot-starter-web
[英]spring-boot-starter-tomcat vs spring-boot-starter-web
我正在嘗試學習Spring啟動,我注意到有兩種選擇。
spring-boot-starter-web - 根據文檔提供對全棧Web開發的支持,包括Tomcat和web-mvc
彈簧引導起動的tomcat
由於#1支持Tomcat,為什么要使用#2?
有什么區別?
謝謝
由於#1支持Tomcat,為什么要使用#2?
spring-boot-starter-web
包含spring-boot-starter-tomcat
。 如果不需要spring mvc,則spring-boot-starter-tomcat
可能會自行使用(包含在spring-boot-starter-web
)。
這是spring-boot-starter-web
的依賴層次結構:
有什么區別?
spring-boot-starter-web
包含spring web依賴項(包括spring-boot-starter-tomcat
):
spring-boot-starter
jackson
spring-core
spring-mvc
spring-boot-starter-tomcat
spring-boot-starter-tomcat
包含與嵌入式tomcat服務器相關的所有內容:
core
el
logging
websocket
如果你想在沒有嵌入式tomcat服務器的情況下使用spring mvc怎么辦?
只需將其從依賴項中排除:
<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>
一個簡單的答案是,並非所有Web應用程序都是SpringMVC應用程序。 例如,如果您希望使用JaxRS,或許您有使用RestTemplate的客戶端應用程序,並且您喜歡它們如何交互它並不意味着您不能使用spring boot或嵌入式tomcat
這是一個使用spring-boot-starter-tomcat
而不是spring-boot-starter-web
的示例應用程序
使用spring-boot-starter-tomcat
在spring boot中使用簡單的Jersey應用程序
同樣重要的是要記住,tomcat不是Spring引導中嵌入式servlet容器的唯一選擇。 使用碼頭也很容易上手。 使用spring-boot-starter-tomcat
可以很容易地將所有模塊排除在一個模塊中,而如果它們都只是spring-web的一部分,那么排除tomcat庫以引入spring-boot-starter-jersey
將會更加成功。
<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>
我在這里從另一個SO問題復制了這段代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.