詳細錯誤代碼:
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target [Bindable@5bf217b type = org.springframework.boot.autoconfigure.web.ResourceProperties, value = 'provided', annotations = array<Annotation>[@org.springframework.boot.context.properties.ConfigurationProperties(prefix=spring.resources, value=spring.resources, ignoreInvalidFields=false, ignoreUnknownFields=false)]] failed:
Property: spring.resources.cache-period
Value: 0
Origin: "spring.resources.cache-period" from property source "refresh"
Reason: The elements [spring.resources.cache-period] were left unbound.
Action:
Update your application's configuration
問題分析
-
何時出現?
- 添加完熱部署依賴,spring-boot-devtools 啟動報錯
-
spring boot 版本:springBootVersion = '2.0.1.RELEASE'
-
devtools 版本:version: '1.5.12.RELEASE'
如何解決
-
既然報錯有錯誤信息就有些頭緒,不難發現:報錯指向 spring.resources.cache-period
-
直接全局搜索:spring.resources.cache-period 發現 前三項都是 springboot 自動配置的 最后devtools 又要配置?
-
進入之后發現 果然 如報錯信息所示:devtools 中靜態塊配置了spring.resources.cache-period 並且value 為 0
-
問題解決:
- 既然devtools 相關jar無法改變,那就是 springboot2.0后不支持老版的devtools ?
- 使用了新版(2.0.0.RELEASE 以上)的 devtools 發現源碼將
spring.resources.cache-period
換成了spring.resources.cache.period
- 再次導入jar后 重啟並不會報錯!
-
總結:
- 遇到問題還是應該仔細看報錯信息
- 多角度的分析 有利於問題的解決 而不是一直盯着一個
-
還有
- 記得剛加完熱部署的依賴時候 啟動並沒有報錯
- 一定是又改動了什么。
- 以后再說~