@MapperScan 注解和 mybatis.mapper-locations 配置兩者缺一不可
@MapperScan(basePackages="xxx.xxx.xxx") 這個注解是用戶掃描 mapper 接口的,也就是dao類;
mybatis.mapper-locations 配置是用於掃描 mapper.xml 的;
兩者用途不同,故缺一不可。
如下,
mybatis:
mapper-locations: classpath:mapping/*Mapping.xml
@MapperScan("com.example.demo.mapper")
如果遇到類似下面的錯誤,通常就是 mapper.xml 文件找不到,請先檢查以上兩個配置是否正常。
例1:
Caused by: org.apache.ibatis.builder.IncompleteElementException: Could not find result map xxx.xxx.xxx.BaseResultMap
例2:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicSecurityMetadataSource': Invocation of init method failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: Could not find result map xxx.xxx.xxx.BaseResultMap
例3:
Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for xxx.xxx.xxx.BaseResultMap
例4:
Could not find result map xxx.xxx.xxx.BaseResultMap
例5:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not fou
原文鏈接和參考資料:
解決org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)問題_寫代碼的蝸牛-CSDN博客 https://blog.csdn.net/sundacheng1989/article/details/81630370
@MapperScan 注解和 mybatis.mapper-locations 配置兩者缺一不可 – CroWall https://crowall.com/archives/mybatis-mapper-scan-and-locations.html