問題
當發起一個請求時報錯如下: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