




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第SpringBoot如何切換成其它的嵌入式Servlet容器(Jetty和Undertow)目錄如何切換成其它的嵌入式Servlet容器(Jetty和Undertow)SpringBoot默認(rèn)使用的內(nèi)置Servlet容器是TomcatSpringBoot還支持Jetty和UndertowSpringBootweb開發(fā)_嵌入式Servlet容器1、切換嵌入式Servlet容器2、定制Servlet容器
如何切換成其它的嵌入式Servlet容器(Jetty和Undertow)
SpringBoot默認(rèn)使用的內(nèi)置Servlet容器是Tomcat
然而SpringBoot還支持其它的Servlet容器默認(rèn)的Tomcat只是其中一種
SpringBoot還支持Jetty和Undertow
Jetty適合用于長鏈接應(yīng)用例如聊天Undertow是一個高性能非阻塞的Servlet容器并發(fā)性能非常好但不支持jsp
若要切換只需要在pom文件中排除自帶的Tomcat啟動器再引入其它Servlet容器的啟動器即可
spring-boot-starter-web里面引入了spring-boot-starter-tomcat因此默認(rèn)使用Tomcat
因此只需排除原先的Tomcat再引入要添加的Servlet容器的依賴即可:
切換成Jetty:
!--引入Web模塊--
dependency
groupIdorg.springframework.boot/groupId
artifactIdspring-boot-starter-web/artifactId
exclusions
!--排除tomcat容器--
exclusion
artifactIdspring-boot-starter-tomcat/artifactId
groupIdorg.springframework.boot/groupId
/exclusion
/exclusions
/dependency
!--引入其它的Servlet容器--
dependency
artifactIdspring-boot-starter-jetty/artifactId
groupIdorg.springframework.boot/groupId
/dependency
Jetty啟動成功
同理切換成undertow:
!--引入Web模塊--
dependency
groupIdorg.springframework.boot/groupId
artifactIdspring-boot-starter-web/artifactId
exclusions
!--排除tomcat容器--
exclusion
artifactIdspring-boot-starter-tomcat/artifactId
groupIdorg.springframework.boot/groupId
/exclusion
/exclusions
/dependency
!--引入其它的Servlet容器--
dependency
artifactIdspring-boot-starter-undertow/artifactId
groupIdorg.springframework.boot/groupId
/dependency
Undertow啟動成功
SpringBootweb開發(fā)_嵌入式Servlet容器
1、切換嵌入式Servlet容器
1.1、SpringBoot支持的Servlet種類及其切換
1)默認(rèn)支持的webServer:Tomcat、Jrtty、Undertow
2)切換服務(wù)器
dependency
groupIdorg.springframework.boot/groupId
artifactIdspring-boot-starter-web/artifactId
exclusions
exclusion
groupIdorg.springframework.boot/groupId
artifactIdspring-boot-starter-tomcat/artifactId
/exclusion
/exclusions
/dependency
1.2、原理
1)SpringBoot應(yīng)用啟動發(fā)現(xiàn)當(dāng)前是Web應(yīng)用。web場景包-導(dǎo)入tomcat
2)web應(yīng)用會創(chuàng)建一個web版的ioc容器ServletWebServerApplicationContext
3)ServletWebServerApplicationContext啟動的時候?qū)ふ襍ervletWebServerFactory(Servlet的web服務(wù)器工廠Servlet的web服務(wù)器)
4)SpringBoot底層默認(rèn)有很多的WebServer工廠;
TomcatServletWebServerFactoryJettyServletWebServerFactoryUndertowServletWebServerFactory
5)底層直接會有一個自動配置類。
ServletWebServerFactoryAutoConfiguration導(dǎo)入了ServletWebServerFactoryConfiguration(配置類)
6)ServletWebServerFactoryConfiguration配置類根據(jù)動態(tài)判斷系統(tǒng)中到底導(dǎo)入了那個Web服務(wù)器的包。(默認(rèn)是web-starter導(dǎo)入tomcat包),容器中就有TomcatServletWebServerFactory
7)TomcatServletWebServerFactory創(chuàng)建出Tomcat服務(wù)器并啟動;TomcatWebServer的構(gòu)造器擁有初始化方法initializethis.tomcat.start();
8)內(nèi)嵌服務(wù)器,就是手動把啟動服務(wù)器的代碼調(diào)用(tomcat核心jar包存在)
2、定制Servlet容器
2.1、修改配置文件
通過對perties配置文件的設(shè)置,定制Servlet容器
#修改servlet容器
server.port=8000
#server.undertow.accesslog.dir=/tmp
2.2、實(shí)現(xiàn)WebServerFactoryCustomizer
xxxxxCustomizer:定制化器,可以改變xxxx的默認(rèn)規(guī)則
通過WebServerFactoryCustomizer修改Servlet容器的響應(yīng)端口號:
importorg.springframework.boot.web.server.WebServerFactoryCustomizer;
importorg.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
importorg.springframework.stereotype.Component;
@Component
publicclassCustomizationBeanimplementsWebServerFactoryCustomizerConfigurableServletWebServerFactory{
@Override
publicvoidcustomize(ConfigurableServletWebServerFactoryserver){
server.setPort(9000);
}
2.3、ConfigurableServletWebServerFactory
直接自定義ConfigurableServletWebServerFactory的接口實(shí)現(xiàn)類
publicinterfaceConfigurableWebServerFactoryextendsWebServerFactory,ErrorPageRegistry{
voidsetPort(intport);
voidsetAddress(InetAddressaddress);
voidsetErrorPages(SetextendsErrorPageerrorPages);
voidsetSsl(Sslssl);
voidsetSslStoreProvider(SslStoreProvidersslStoreProvider);
voidsetHttp2(Http2http2);
voidsetCompression(Compressioncompression);
voidsetServerHeader(StringserverHeader);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 教育數(shù)字化轉(zhuǎn)型中的技術(shù)工具與平臺發(fā)展
- 2024年昭通市工會招聘社會工作專業(yè)人才筆試真題
- 2025廣東交通職業(yè)技術(shù)學(xué)院單招《職業(yè)適應(yīng)性測試》考試黑鉆押題(精練)附答案詳解
- 2024年中國煙草總公司上海市公司考試真題試卷及答案
- 窗簾材質(zhì)培訓(xùn)課件
- 2024內(nèi)蒙古豐州職業(yè)學(xué)院單招《物理》模考模擬試題附答案詳解【培優(yōu)A卷】
- 即興伴奏培訓(xùn)課件圖片
- 江蘇省揚(yáng)州市2026屆高三第四次模擬考試生物試題
- ICU氣管插管的護(hù)理
- 居家養(yǎng)老服務(wù)志愿者培訓(xùn)
- 新能源汽車充電站建設(shè)合作協(xié)議
- 出院病人終末消毒流程
- 山西焦煤招聘2025筆試題庫
- star法則培訓(xùn)課件
- 手術(shù)室護(hù)士自我簡介
- 地下管線保護(hù)和加固措施
- 廣告公司分支機(jī)構(gòu)合同
- 2024年新課標(biāo)培訓(xùn)2022年小學(xué)英語新課標(biāo)學(xué)習(xí)培訓(xùn)課件
- 2024年北京第二次高中學(xué)業(yè)水平合格考地理試卷真題(含答案詳解)
- 計(jì)算機(jī)網(wǎng)絡(luò)與信息安全(2024年版)課件全套 李全龍 第01-10章 計(jì)算機(jī)網(wǎng)絡(luò)與信息安全概述- 網(wǎng)絡(luò)安全協(xié)議與技術(shù)措施
- 創(chuàng)建二級甲等醫(yī)院實(shí)施方案
評論
0/150
提交評論