spring boot 靜態資源

2021-10-04 20:12:51 字數 706 閱讀 2347

springboot中,預設的靜態資源路徑有:

配置在resourceproperties類中

private static final string classpath_resource_locations = 

;

優先順序:

靜態資源路徑:

例如: 

webmvcautoconfiguration自動裝配類中,可以看到首頁定義:
是靜態資源下面的名稱為index.html 

現在在4個路徑中分別新增index.html    http://localhost:8080/  檢查優先順序順序:

"classpath:/meta-inf/resources/",     1

"classpath:/resources/",    2

"classpath:/static/",     3

"classpath:/public/"    4

springboot載入靜態資源

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

Spring Boot 靜態資源處理

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

springboot 訪問靜態資源

最近在做springboot 專案遇到靜態資源訪問問題,在這裡記錄下,可以給他人參考避免踩坑 問題點 sprignboot專案建立時預設自動建立靜態資源資料夾resources static和resources templates,預設可直接訪問靜態資源路勁有四類 static,public,res...