@MapperScan 注解和 mybatis.mapper-locations 配置两者缺一不可

  • @MapperScan(basePackages="xxx.xxx.xxx") 这个注解是用户扫描 mapper 接口的,也就是dao类;
  • mybatis.mapper-locations 配置是用于扫描 mapper.xml 的;

两者用途不同,故缺一不可。

如果遇到类似下面的错误,通常就是 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

标签: none

添加新评论