org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 錯誤解決方式
阿新 • • 發佈:2022-05-09
起因:
在打包後執行jar包是會出現如下錯誤:
Invocation of init method failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):com.***.***.;
分析:
主觀分析:
應該是nacespace或者註解掃描位置錯誤導致無法載入xml檔案。
解決方式:
1、檢查nacespace是否一致
2、檢查配置檔案中的包掃描位置是否正確
結果:
namespace配置、方法名稱、包掃描位置都正確。但是依舊會出現如上錯誤。
查詢前人踩過的坑:
再次嘗試解決:
1、按照文章中的兩部操作
1、檢查target資料夾下的mapper
發現是將其編譯進去了
2、在pom中新增resource標籤,將靜態檔案強制打包進去
結果:
push之後使用Jenkins+docker釋出依舊是最開始的錯誤。
最終嘗試:
將線上打包的jar下載到本地。解壓後發現了問題所在:
線上Jenkins拉去程式碼後並沒有按照約定的建一個mapper/job資料夾,而是直接建了一個mapper.job的資料夾。
而配置檔案中做的掃描位置又是classpath:mapper/**/*.xml 與目前jar中的檔名不匹配,所以無法載入。
解決方式:
讓mapper.job包建為兩個資料夾即可。博主採用的是在mapper資料夾下建立了一個月job資料夾同級的README.md檔案。
解決的同時還可以提醒後期接手小夥伴。