現象:
1、此工程之前實際正常 Run/Debug 過,每次修改代碼會在 idea 中重新 package 打包;
2、偶然執行 Run/Debug 均報告 active: @profile.name@ 相關的錯誤信息,重新打包后依然報錯;
分析及解決:
1、基于 active: @profile.name@ 及啟動日志信息,明確 springboot 啟用了 @...@ 動態獲取配置的意圖;
2、檢查 idea 中 maven 插件,確保有選中合適的 profile 選項(有必要到根 pom.xml 中檢查對應項);
2.a、若多選 maven 插件中的多個 profile 選項,則會按 pom.xml 中物理可用的最后一個來處理;
2.b、若全部不選、多選但全部沒有對應項,則 @profile.name@ 無法被動態轉譯,進而保留不變;
3、在 maven 插件中選擇 compile/package,隨后 target/classes/application.yml 中查看結果;
參考:
1、
while scanning for the next tokenfound character ‘@‘ that cannot start any token.2、
聊聊 SpringBoot 中的兩種占位符:@*@ 和 ${*}3、
在構建時期自動擴展info屬性4、
SpringBoot配置文件5、
Spring Boot中YAML屬性配置文件使用詳解6、
Spring boot2 使用profile 配置多環境7、
Could not resolve placeholder ‘xxx‘ in value “${xxx}“