springboot靜態資源對映

2022-03-07 17:55:04 字數 902 閱讀 5608

1、webjars:springboot中以jar包形式引入的靜態資源

所有 /webjars/** ,都去classpath:/meta-inf/resources/webjars/找資源;

webjars官網:

匯入靜態資源後,資源訪問路徑為:

如圖所示:訪問jquery.js的路徑為:localhost:8080/webjars/jquery/3.4.1/jquery.js

2、如果是自己的靜態資源檔案,springboot預設是從以下這些路徑中讀取的

"classpath:/meta‐inf/resources/", 

"classpath:/resources/",

"classpath:/static/",

"classpath:/public/"

"/":當前專案的根路徑

3、springboot預設首頁面為index.html在springboot預設靜態資源訪問路徑下新增名為index.html檔案,那麼訪問localhost:8080,會自動跳轉到這個index.html

# 自定義靜態資源訪問路徑,可以指定多個,之間用逗號隔開

spring.resources.static-locations=classpath:/mystatic/,classpath:/mypublic

注意:自定義靜態資源後,springboot預設的靜態資源路徑將不再起作用實現類 此方法註冊新的url位址

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...