1.spring.mvc.static-path-pattern
這個配置項是告訴springboot,應該以什麼樣的方式去尋找資源。預設配置為 /* 。換句話說,只有靜態資源滿足什麼樣的匹配條件,spring boot才會處理靜態資源請求
如果原先訪問首頁的位址是:http://localhost:8888/index.html
那麼在你配置這個配置後,上面的訪問就失效了,現在訪問同樣的頁面需要這樣訪問:http://localhost:8888/soul/index.html
2.spring.resources.static-locations
這個配置項是告訴springboot去哪找資源。
# 預設值為
spring.resources.static-locations=classpath:/meta-inf/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
根據前後關係確定優先順序
可通過配置檔案配置
mvc:static-path-pattern: /note/*
* resources:
static-locations: classpath:/resources/note/
也可通過配置類註解
@configuration注意:public
class
webconfig implements webmvcconfigurer
}
classpath 是指編譯後classes 檔案目錄的相對路徑

spring boot 靜態資源
springboot中,預設的靜態資源路徑有 配置在resourceproperties類中 private static final string classpath resource locations 優先順序 靜態資源路徑 例如 webmvcautoconfiguration自動裝配類中,可...
SpringMVC REST 風格靜態資源訪問配置
1 在web.xml中使用預設servlet處理靜態資源,缺點是如果靜態資源過多,則配置量會比較大,一旦有遺漏,則會造成資源無法正常顯示或404錯誤。2 在springmvc配置檔案中配置 我的所有靜態資源都在webcontent static 之下,下有如下目錄webcontent static ...
springboot載入靜態資源
使用springboot寫了簡單的web專案,頁面使用jsp檔案 但是靜態資源js 載入不到,看了下官方文件發現是因為路徑不對 所以專案靜態資源應該配置在根路徑下這四個資料夾中是可以直接訪問到的 meta inf resources,public,resources,static下的資源,對映路徑 ...