这种情况通常情况下是由于Mapper映射xml文件中SQL标签的id属性重复导致的,仔细检查是否有相同的sql方法名称。
解决方法:
- 1.检查是否有重复id标签的sql;
- 2.配置项mybatis: mapper-locations:重复,导致在程序加载时,多次编译xml文件,一个方法被加载两次,就会检测到重复;
我遇到的是第二种情况,确定自己的xml确实不存在重复的sql方法名,检查到我这里的配置项重复:
mybatis:
mapper-locations:
# - classpath:mapper/single/*.xml
# - classpath:mapper/complex/*.xml
- classpath*:mapper/single/*.xml
- classpath*:mapper/complex/*.xml
这里两个配置的区别是:
classpath*:加载多模块的mapper的namespace空间;
classpath:项目中只有单个模块,使用该配置进行加载;