背景:
这里我想用xml映射文件,但是一直读不到xml文件,其实就是少在配置中心yml加扫描,但是由于各种原因,我这边忽视了,踩了好多坑。
# 读取xml文件
mybatis.mapper-locations= classpath:mapper/*.xml
场景复现:
场景一:
如果你遇见能进service并且xml语句可以运行,换一种就是使用mybatis注解可以但是xml文件不可以,那不用说,九成就是没加读取文件。
场景二:
如果你遇见报错如下:
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
恭喜你,仅仅是读取语句写错了,我估计你应该是写成了
# 读取xml文件
mybatis.config-locations= classpath:mapper/*.xml
这个是config的配置路径
请改成
# 读取xml文件
mybatis.mapper-locations= classpath:mapper/*.xml
场景三:
这个原因是你实体类和数据库没照应,例如我的场景是实体类多加了一个属性,但是数据库字段并没有相应更新,所以说也会出现标题所述,此时你可以添加上去,我的这个因为是半路接手,文档不全就没咋管,谁知道会出现这个情况。