一、問題描述
在學習SpringBoot配置profile的時候,.yml文件內(nèi)容明明跟老師敲的一模一樣,但還是報錯ERROR org.springframework.boot.SpringApplication -- Application run failed
原.yml文件內(nèi)容:
---
server :
port : 8081
spring:
profiles: dev
---
server :
port : 8082
spring:
profiles: test
---
server :
port : 8083
spring:
profiles: pro
---
spring:
profiles:
active: pro
報錯如下:
?二、解決方法
按照“ERROR org.springframework.boot.SpringApplication -- Application run failed”搜索答案,試了好久都沒能解決,還是回過頭來一句句分析自己的報錯情況吧!
發(fā)現(xiàn)報錯中提示“?Property 'spring.profiles' imported from location 'class path resource [application.yml]' is invalid and should be replaced with 'spring.config.activate.on-profile'...”,感悟到一點意思了,spring.profiles應該被spring.config.activate.on-profile代替。
"spring.profiles"我在yml文件里寫過,懷疑是不是要改為spring.config.activate.on-profile的意思。將原句刪除后,當輸入s時提示框里便出現(xiàn)了“spring.config.activate.on-profile”,果不其然。
?得出兩點體悟:
1、不要死讀書不變通,老師講的內(nèi)容照抄照搬過來不一定在自己的環(huán)境版本下運行順利;
2、遇事應沉著冷靜,不要胡亂發(fā)力,找準痛點,扎扎實實去分析解決。
三、修改之后的.yml文件內(nèi)容
---
server :
port : 8081
spring:
config:
activate:
on-profile: dev
---
server :
port : 8082
spring:
config:
activate:
on-profile: test
---
server :
port : 8083
spring:
config:
activate:
on-profile: pro
---
spring:
profiles:
active: pro
四、控制臺運行結(jié)果
文章來源:http://www.zghlxwxcb.cn/news/detail-536155.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-536155.html
到了這里,關于【Spring Boot基礎】解決ERROR org.springframework.boot.SpringApplication -- Application run failed報錯問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!