国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - Java教程 - SpringBoot深入理解之內置web容器及配置的總結

SpringBoot深入理解之內置web容器及配置的總結

2021-07-21 14:20Super_PF Java教程

今天小編就為大家分享一篇關于SpringBoot深入理解之內置web容器及配置的總結,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

前言

在學會基本運用springboot同時,想必搭過ssh、ssm等開發框架的小伙伴都有疑惑,springboot在spring的基礎上做了些什么,使得使用springboot搭建開發框架能如此簡單,便捷,快速。本系列文章記錄網羅博客、分析源碼、結合微薄經驗后的總結,以便日后翻閱自省。

正文

使用springboot時,首先引人注意的便是其啟動方式,我們熟知的web項目都是需要部署到服務容器上,例如tomcat、weblogic、widefly(以前叫jboss),然后啟動web容器真正運行我們的系統。而springboot搭建的系統卻是運行***application.class中的main方法啟動。這是為什么?

原因是springboot除了高度集成封裝了spring一系列框架之外,還封裝了web容器,springboot啟動時會根據配置啟動相應的上下文環境,查看embeddedservletcontainerautoconfiguration源碼可知(這里springboot啟動過程會單獨總結分析),如下。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@autoconfigureorder(-2147483648)
@configuration
@conditionalonwebapplication
@import({embeddedservletcontainerautoconfiguration.beanpostprocessorsregistrar.class})
public class embeddedservletcontainerautoconfiguration {
  ...
  ...(中間省略部分)
  @configuration
  @conditionalonclass({servlet.class, undertow.class, sslclientauthmode.class})//undertow配置判斷
  @conditionalonmissingbean(
    value = {embeddedservletcontainerfactory.class},
    search = searchstrategy.current
  )
  public static class embeddedundertow {
    public embeddedundertow() {
    }
    @bean
    public undertowembeddedservletcontainerfactory undertowembeddedservletcontainerfactory() {
      return new undertowembeddedservletcontainerfactory();
    }
  }
  @configuration
  @conditionalonclass({servlet.class, server.class, loader.class, webappcontext.class})//jetty配置判斷
  @conditionalonmissingbean(
    value = {embeddedservletcontainerfactory.class},
    search = searchstrategy.current
  )
  public static class embeddedjetty {
    public embeddedjetty() {
    }
    @bean
    public jettyembeddedservletcontainerfactory jettyembeddedservletcontainerfactory() {
      return new jettyembeddedservletcontainerfactory();
    }
  }
  @configuration
  @conditionalonclass({servlet.class, tomcat.class})//tomcat配置判斷,默認為tomcat
  @conditionalonmissingbean(
    value = {embeddedservletcontainerfactory.class},
    search = searchstrategy.current
  )
  public static class embeddedtomcat {
    public embeddedtomcat() {
    }
    @bean
    public tomcatembeddedservletcontainerfactory tomcatembeddedservletcontainerfactory() {
      return new tomcatembeddedservletcontainerfactory();
    }
  }
}

該自動配置類表明springboot支持封裝tomcat、jetty和undertow三種web容器,查看spring-boot-starter-web的pom.xml(如下),其默認配置為tomcat。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelversion>4.0.0</modelversion>
  <parent>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starters</artifactid>
    <version>1.5.8.release</version>
  </parent>
  <artifactid>spring-boot-starter-web</artifactid>
  <name>spring boot web starter</name>
  <description>starter for building web, including restful, applications using spring
    mvc. uses tomcat as the default embedded container</description>
  <url>http://projects.spring.io/spring-boot/</url>
  <organization>
    <name>pivotal software, inc.</name>
    <url>http://www.spring.io</url>
  </organization>
  <properties>
    <main.basedir>${basedir}/../..</main.basedir>
  </properties>
  <dependencies>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter</artifactid>
    </dependency>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-tomcat</artifactid>
    </dependency>
    ...
    ...

若我們使用其他容器,該如何配置,例如該篇文章Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers詳細比較了springboot中三種容器的性能、穩定性等,結果證明了undertow在性能和內存使用上是最好的。

顯然,更換內置容器,能提高springboot項目的性能,由于springboot插拔式的模塊設計,配置undertow只需要兩步,如下。

1.第一步,去除原容器依賴,加入undertow依賴。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<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-undertow</artifactid>
</dependency>

2.第二步,在application.yml中配置undertow。

?
1
2
3
4
5
6
7
8
9
10
11
12
server.undertow.accesslog.dir= # undertow access log directory.
server.undertow.accesslog.enabled=false # enable access log.
server.undertow.accesslog.pattern=common # format pattern for access logs.
server.undertow.accesslog.prefix=access_log. # log file name prefix.
server.undertow.accesslog.rotate=true # enable access log rotation.
server.undertow.accesslog.suffix=log # log file name suffix.
server.undertow.buffer-size= # size of each buffer in bytes.
server.undertow.buffers-per-region= # number of buffer per region.
server.undertow.direct-buffers= # allocate buffers outside the java heap.
server.undertow.io-threads= # number of i/o threads to create for the worker.
server.undertow.max-http-post-size=0 # maximum size in bytes of the http post content.
server.undertow.worker-threads= # number of worker threads.

其余對容器的更多配置,調優等等不作介紹,可以自行百度undertow。

到這里,肯定會有很多人有疑惑,非得用springboot集成的容器作為運行環境嗎?答案是:no! springboot同樣提供了像往常一樣打war包部署的解決方案。

1.將項目的啟動類application.java繼承springbootservletinitializer并重寫configure方法。

?
1
2
3
4
5
6
7
8
9
10
@springbootapplication
public class application extends springbootservletinitializer {
  @override
  protected springapplicationbuilder configure(springapplicationbuilder application) {
    return application.sources(application.class);
  }
  public static void main(string[] args) throws exception {
    springapplication.run(application.class, args);
  }
}

2.在pom.xml文件中,< project >標簽下面添加war包支持的< package >標簽,或者將原標簽值jar改成war。

?
1
<packaging>war</packaging>

3.在pom.xml文件中,去除tomcat依賴,或者將其標記為provided(打包時排除),provided方式有一點好處是調試是可以用內置tomcat。

?
1
2
3
4
5
<dependency>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-tomcat</artifactid>
    <scope>provided</scope>
</dependency>

至此,以上3個配置便可以完成war方式部署,注意war包部署后訪問時需要加上項目名稱。

最后,對比傳統應用容器和springboot容器架構圖。

傳統應用容器:

SpringBoot深入理解之內置web容器及配置的總結

springboot容器:

SpringBoot深入理解之內置web容器及配置的總結

springboot這種設計在微服務架構下有明顯的優點:

  • 可以創建獨立、自啟動的應用容器
  • 不需要構建war包并發布到容器中,構建和維護war包、容器的配置和管理也是需要成本和精力的
  • 通過maven的定制化標簽,可以快速創建springboot的應用程序
  • 可以最大化地自動化配置spring,而不需要人工配置各項參數
  • 提供了產品化特點,例如:性能分析、健康檢查和外部化配置
  • 全程沒有xml配置,也不需要代碼生成

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接

原文鏈接:https://blog.csdn.net/u011961421/article/details/79732924

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 久久成人精品 | 91新视频 | 日韩一区欧美 | 日韩欧美一区二区三区 | 三级黄色片在线观看 | 精品国产一区探花在线观看 | 欧美日本精品 | 最新中文字幕在线 | 免费看黄在线网站 | 国产久| 欧美精品影院 | 成人国产精品久久久 | 成人在线视频观看 | 成人精品视频在线观看 | 欧美一级二级三级视频 | 久久久久99| 懂色aⅴ精品一区二区三区蜜月 | 最近2019年好看中文字幕视频 | 日韩一二区 | 亚洲精品免费观看 | 中文字幕在线免费视频 | 精品成人一区 | 亚洲高清视频在线 | 欧美 中文字幕 | 免费在线观看一区二区三区 | 成人高清视频在线观看 | 久久久综合网 | 精品国产乱码久久久久久牛牛 | 欧美freesex黑人又粗又大 | av男人的天堂在线 | 欧美一区在线观看视频 | 在线观看成人 | 久久国产亚洲 | 欧美日韩精品一区二区三区蜜桃 | 大香一网| 国精品一区二区三区 | 欧美精品99 | 亚洲国产精品一区 | 人人做人人澡人人爽欧美 | 精品久久久久久久久久久久久久久久久久 | 精品一区久久 |