SpringBoot靜態資源配置

2021-08-17 10:34:01 字數 951 閱讀 3464

1:springboot靜態資源配置,使用 webmvcautoconfiguration配置各種屬性。

springboot 預設將 /** 所有訪問對映到以下路徑

classpath:/static

classpath:/public

classpath:/resources

classpath:/meta-inf/resources

2:如果想要自定義靜態資源的訪問路徑,可以定義乙個config類並繼承webmvcconfigureradapter類,通過重寫 addresourcehandlers方法配置靜態資源訪問路徑(ps:在實踐中發現只要配置類extends webmvcconfigureradapter並開啟@enablewebmvc,就必須在重寫的addresourcehandlers方法中配置預設靜態資源訪問路徑,否則預設的靜態資源也無法訪問)

在yml檔案中配置靜態資源對映路徑

######

######

######

# zyframework配置 ###################

zyframework:

filerepository: #檔案資源引數配置

dfsroot: g:/dfs #本地或分布式儲存根路徑

resourcepathmap: /u/**->

file:$/u/,/**->classpath:/static/

#資源對映路徑(->標識:key/value ,標識:分隔符)

靜態資源對映**:

@configuration

@enablewebmvc

public class mymvcconfig extends webmvcconfigureradapter

super.addresourcehandlers(registry);

}

spring boot 靜態資源

springboot中,預設的靜態資源路徑有 配置在resourceproperties類中 private static final string classpath resource locations 優先順序 靜態資源路徑 例如 webmvcautoconfiguration自動裝配類中,可...

springboot載入靜態資源

使用springboot寫了簡單的web專案,頁面使用jsp檔案 但是靜態資源js 載入不到,看了下官方文件發現是因為路徑不對 所以專案靜態資源應該配置在根路徑下這四個資料夾中是可以直接訪問到的 meta inf resources,public,resources,static下的資源,對映路徑 ...

Spring Boot 靜態資源處理

在web開發中,靜態資源的訪問是必不可少的,如 js css 等資源的訪問。spring boot 對靜態資源訪問提供了很好的支援,基本使用預設配置就能滿足開發需求。spring boot 對靜態資源對映提供了預設配置 spring boot 預設將 所有訪問對映到以下目錄 classpath st...