springboot webmvc 自動配置

2021-07-26 09:26:49 字數 2737 閱讀 9510

通過webmvcautoconfiguration發現spring boot做了許多自動配置。

1.自動配置的veiwresolver

contentnegotiatingviewresolver:自身不處理view,而是**給不同的viewresovler來處理不同的view,優先順序最高。

public

contentnegotiatingviewresolver

viewresolver

(beanfactory beanfactory)

beannameviewresolver:根據controller方法中返回的字串的view來渲染檢視。

@bean

@conditionalonbean

()@conditionalo****singbean

public beannameviewresolver beannameviewresolver

()

internalresourceviewresolver:主要通過設定字首、字尾以及控制器方法中返回的檢視名字串得到實際頁面。

@bean

@conditionalo****singbean

public internalresourceviewresolver defaultviewresolver

()

2.自動配置的靜態資源

在自動配置類中addresourcehandlers方法中定義了以下靜態資源配置,可繼承起抽象父類,覆寫該方法進行擴充套件。

public

void

addresourcehandlers

(resourcehandlerregistry registry)

else ).addresourcelocations(new

string).setcacheperiod(cacheperiod));

}string staticpathpattern = this.mvcproperties.getstaticpathpattern();

this.customizeresourcehandlerregistration(registry.addresourcehandler(new

string).addresourcelocations(this.resourceproperties.getstaticlocations()).setcacheperiod(cacheperiod));}}

}

類路徑檔案
private

static

final

string classpath_resource_locations = new

string;

把類路徑下的/static、/public、/resources和/meta-inf/resources資料夾下的靜態檔案直接對映為/**。

webjar 

將常用的指令碼框架封裝在jar包中,把webjar的/meta-inf/resources/webjars/下的靜態檔案對映為/webjar/**,可以通過http://ip:port/webjar/**訪問。

3.自動配置的formatter和converter

public

void

addformatters

(formatterregistry registry)

var2 = this.getbeansoftype(genericconverter.class).iterator();

while(var2.hasnext())

var2 = this.getbeansoftype(org.springframework.format.formatter.class).iterator();

while(var2.hasnext())

}

只要我們程式中自定義了converter、genericconverter和formatter介面的實現類bean,這些bean就會自動註冊到spring mvc中。

4.自動配置的httpmessageconverters

webmvcautoconfiguration中,註冊了messageconverters

如果要新增自定義的httpmessageconverter,則只要定義乙個自己的httpmessageconverters的bean,在bean中註冊 定義好的httpmessageconverter即可。

()5.靜態首頁的支援

classpath:/meta-inf/resources/index.html

classpath:/resources/index.html

classpath:/static/index.html

classpath:/public/index.html

Quality Center自動傳送郵件配置

quality center 自動傳送郵件配置 1.配置郵件伺服器 登入siteadmin 站點配置 郵件協議 設定 設定郵件協議 smtp伺服器,輸入內網郵件伺服器ip,公司內網伺服器為為 設定了以後頁面會顯示 mail protocol smtp mail server host 2.配置自動傳...

vim外掛程式自動補齊 Vim 自動補全等外掛程式配置操作

vim的所有配置都是寫在.vimrc這個檔案裡的,我們先建立該檔案。cd touch vimrc vim vimrc 建立完成後,寫入一些基礎配置,引號內是注釋 去掉vi的一致性 set nocompatible 顯示行號 set number 隱藏滾動條 set guioptions r set ...

Ubuntu 手動配置IP和dhcp自動配置IP

ubuntu網路配置如下 ubuntu上連了兩塊網絡卡,eth0為外網的eth1為內網的eth0上ip為自動獲取eth1上為手工設定 1 開啟ubuntu的 etc network inte ces檔案 預設內容如下 auto lo iface lo inet loopback 2 如果以dhcp方...