從配置文件讀取配置信息給配置類屬性賦值 - 處理過程由springboot實現(該過程暫未分析)
【配置文件:application.yml 與 springboot內置配置類的 聯系】
總結:
自動配置類關聯Properties類,properties類中存在默認屬性值,
而properties關聯application.yml,在application.yml中的配置會更改properties中的屬性值
【application.yml中可以配置哪些內容?】
由官方約定
(1)spring官網查看:
https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#server-properties
(2)在自動配置類中查看
找自動配置類:
spring.factories -> 中任意一全限定類名 (idea中點擊可跳轉)
配置類 -> 對應一個xxxProperties 其屬性(有的好像沒有?) -> 對應配置文件中可修改的屬性
【application.yml中的一些配置】
# 查看那些配置生效,那些配置沒生效
debug:true 啟動項目控制台查看日志;
# 靜態資源訪問路徑 -官方配置的 CLASSPATH_RESOURCE_LOCATIONS = new String[] {"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"}; spring: mvc: static-path-pattern: xxxxxx --可自定義配置的路徑 注:springboot使用 WebJars 統一管理靜態資源 eg: xxx.js
(1)在pom中導入依賴:從 https://www.webjars.org/ 官網找 (2)訪問路徑為 /webjars/** - 資源存在路徑為 classpath:/META-INF/resources/webjars/