第一种:xml文件目录填写错误
1.做新项目的时候遇到这个问题:
原因是mapper.xml文件的目录命名直接用的com.dehua.seckill.infrastructure.mapper,
他会把整个当成目录名称,不会有层级结构
应该这样:com/dehua/seckill/infrastructure/mapper创建文件目录
2.通过查看target目录发现2种目录名称的层级目录都不一样
com/dehua/seckill/infrastructure/mapper的层级目录
com.dehua.seckill.infrastructure.mapper的层级目录
解决方法:把com.dehua.seckill.infrastructure.mapper改为 com/dehua/seckill/infrastructure/mapper
第二种 没有配置mapper-locations
mapper-locations是一个定义mapper位置的属性
如果mapper接口和xml包文件路径一样就不需要配置
比如:mapper接口=com.dehua.seckill.infrastructure.mapper.testMapper.java
*.xml文件=com/dehua/seckill/infrastructure/mapper/testMapper.xml
如果*.xml文件=com/dehua/mapper/testMapper.xml
需要配置
mybatis.mapper-locations: classpath:/com/dehua/**/*.xml
解决方案:1.mapper接口和xml包文件路径 配置一样
2.yml文件添加mybatis.mapper-locations: classpath:/目录名称/**/*.xml