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