springboot 訪問靜態資源設定

2021-08-22 13:21:58 字數 844 閱讀 3698

今天乙個人問我為什麼專案下的不能訪問,幫他解決問題後我決定記錄下來,springboot 的程式的靜態資源訪問需要重寫addresourcehandlers方法,直接上**:

import org.springframework.context.annotation.configuration;

import org.springframework.core.ordered;

import org.springframework.web.servlet.config.annotation.resourcehandlerregistry;

import org.springframework.web.servlet.config.annotation.viewcontrollerregistry;

import org.springframework.web.servlet.config.annotation.webmvcconfigurer;

@configuration

//存放靜態資源的位址

private static final string root = "d:/test/systemfile";

@override

public void addresourcehandlers(resourcehandlerregistry registry)

@override

public void addviewcontrollers( viewcontrollerregistry registry )

}

@servletcomponentscan 註解

簡單的實現springboot靜態資源訪問。

springboot資靜態資源訪問自定義

官方文件 介紹了可以自配置的一些東西,下面我來嘗試。public resources meta inf resources這些資料夾都是建在resources目錄下的。想要修改訪問的路徑,比如想要用 res air.jpg訪問,就得自定義了,做法是在配置檔案中 這裡使用yaml 這樣寫 spring...

SpringBoot Web開發 訪問靜態資源

webmvcauotconfiguration類下的addresourcehandlers 方法 就是新增資源對映 resourceproperties 設定和靜態資源有關的引數,如快取時間等 webjars 以jar包的方式引入靜態資源 引入webjars依賴 我們可從webjars 找到我們想要...

SpringBoot建立web專案靜態資源路徑配置

spring boot檢視配置 spring.mvc.view.prefix web inf views spring.mvc.view.suffix jsp 靜態檔案訪問配置 spring.mvc.static path pattern static 但是,配置完不起作用,每次訪問能進後台cont...