@MapperScan 注解和 mybatis.mapper-locations 配置两者缺一不可
@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