




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第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適合用于長(zhǎng)鏈接應(yīng)用例如聊天Undertow是一個(gè)高性能非阻塞的Servlet容器并發(fā)性能非常好但不支持jsp
若要切換只需要在pom文件中排除自帶的Tomcat啟動(dòng)器再引入其它Servlet容器的啟動(dòng)器即可
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啟動(dòng)成功
同理切換成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啟動(dòng)成功
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)用啟動(dòng)發(fā)現(xiàn)當(dāng)前是Web應(yīng)用。web場(chǎng)景包-導(dǎo)入tomcat
2)web應(yīng)用會(huì)創(chuàng)建一個(gè)web版的ioc容器ServletWebServerApplicationContext
3)ServletWebServerApplicationContext啟動(dòng)的時(shí)候?qū)ふ襍ervletWebServerFactory(Servlet的web服務(wù)器工廠Servlet的web服務(wù)器)
4)SpringBoot底層默認(rèn)有很多的WebServer工廠;
TomcatServletWebServerFactoryJettyServletWebServerFactoryUndertowServletWebServerFactory
5)底層直接會(huì)有一個(gè)自動(dòng)配置類。
ServletWebServerFactoryAutoConfiguration導(dǎo)入了ServletWebServerFactoryConfiguration(配置類)
6)ServletWebServerFactoryConfiguration配置類根據(jù)動(dòng)態(tài)判斷系統(tǒng)中到底導(dǎo)入了那個(gè)Web服務(wù)器的包。(默認(rèn)是web-starter導(dǎo)入tomcat包),容器中就有TomcatServletWebServerFactory
7)TomcatServletWebServerFactory創(chuàng)建出Tomcat服務(wù)器并啟動(dòng);TomcatWebServer的構(gòu)造器擁有初始化方法initializethis.tomcat.start();
8)內(nèi)嵌服務(wù)器,就是手動(dòng)把啟動(dòng)服務(wù)器的代碼調(diào)用(tomcat核心jar包存在)
2、定制Servlet容器
2.1、修改配置文件
通過(guò)對(duì)perties配置文件的設(shè)置,定制Servlet容器
#修改servlet容器
server.port=8000
#server.undertow.accesslog.dir=/tmp
2.2、實(shí)現(xiàn)WebServerFactoryCustomizer
xxxxxCustomizer:定制化器,可以改變xxxx的默認(rèn)規(guī)則
通過(guò)WebServerFactoryCustomizer修改Servlet容器的響應(yīng)端口號(hào):
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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025四川瀘州交通物流集團(tuán)有限公司及下屬公司招聘12人筆試參考題庫(kù)附帶答案詳解析
- 家庭教育指導(dǎo)服務(wù)行業(yè)2025年市場(chǎng)細(xì)分領(lǐng)域競(jìng)爭(zhēng)態(tài)勢(shì)研究報(bào)告
- 跨文化領(lǐng)導(dǎo)力挑戰(zhàn)解析試題及答案
- 餐飲企業(yè)食品安全與責(zé)任保險(xiǎn)合同范本
- 高端會(huì)所家具定制與采購(gòu)協(xié)議
- oppo校招筆試題目及答案
- 上市公司股權(quán)代持監(jiān)管執(zhí)行合同
- 餐飲行業(yè)跨界合作股權(quán)轉(zhuǎn)讓合同
- JAVA網(wǎng)絡(luò)通信原理解析試題及答案
- 老城雨污分流管網(wǎng)提標(biāo)改造工程項(xiàng)目總體規(guī)劃
- 眼球的結(jié)構(gòu)與功能
- 《社會(huì)主義制度在中國(guó)的確立》示范課教學(xué)設(shè)計(jì)【高中思想政治人教版必修1中國(guó)特色社會(huì)主義】
- 立方米臥式濃硫酸儲(chǔ)罐設(shè)計(jì)
- 三乙胺安全標(biāo)簽
- GB/T 4490-2021織物芯輸送帶寬度和長(zhǎng)度
- GB/T 28650-2012公路防撞桶
- GB/T 17793-1999一般用途的加工銅及銅合金板帶材外形尺寸及允許偏差
- ICU常見(jiàn)檢查項(xiàng)目及課件
- 土地荒漠化的防治(公開課)課件
- MSA量測(cè)系統(tǒng)分析RMSA量測(cè)系統(tǒng)分析課件
- 中考備考應(yīng)對(duì)中考?xì)v史學(xué)科的復(fù)習(xí)策略和解題技巧課件
評(píng)論
0/150
提交評(píng)論