spring boot多模塊,請求時報錯如下:Invalid bound statement (not found)

問題

當發起一個請求時報錯如下:Invalid bound statement (not found): com.xxx.xxx.configcenter.common.mapper.ConfigDataMapper.saveConfigData

場景

本人的項目是一個多模塊的項目,其中模塊B依賴模塊A,模塊A的application.yml中配置如下:

mybatis:
  mapper-locations: classpath:mappers/*.xml

而模塊B中無此配置,當針對模塊B的請求在模塊B代碼中調用模塊A的resources下面的mappers/*.xml時報錯,於是就出現了上面的問題

原因

mapper-locations: classpath*:mappers/*.xml這個配置,只會掃描啓動模塊resources下的mappers/*.xml配置,並不會對其它模塊進行掃描

解決

將模塊A中的配置改爲如下,即在classpath後面緊跟一個星號("*"), 這樣就會加載所有模塊resources下的mappers/*.xml配置

mybatis:
  mapper-locations: classpath*:mappers/*.xml

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章