mybatis-plus Invalid bound statement (not found)
最近把maven项目变成了多模块的项目模块如下db
类的都在dao层下
发现报错信息Invalid bound statement (not found)
,而且出现注入接口的时候
@Component
public class ModelConverterReceiver {
@Autowired
private MessageProcess process;
}
提示
required a single bean, but 2 were found
当时我就奇怪了
public interface MessageProcess {
}
@service
public class ObjectAttributeMessageProcess implements MessageProcess{
}
明明是一个接口,怎么就提示我有两个bean了。尝试多次,发现还是报这个错,所以无奈之下,改成这样
public interface MessageProcess {
}
@service
@primary
public class ObjectAttributeMessageProcess implements MessageProcess{
}
接下来测试查询的时候
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zzy.engine.service.ScheduleJobService.page
提示我invalid bound statement
。
一开始怀疑是mybatis configuration初始化的时候没有存储mappedstatemetn,断点查看
发现当前对象被mybatis plus代理了
这里很关键
继续断点
com.baomidou.mybatisplus.core.override.MybatisMapperMethod.SqlCommand#SqlCommand
发现configuration中mappedStatements中不为空,说明mybatis解析了我的xml文件,配置是没有问题的,继续断点
com.baomidou.mybatisplus.core.override.MybatisMapperMethod.SqlCommand#resolveMappedStatement
发现当前statementid不正确,不应该是service的对应方法。
沉默许久,结合之前的问题,突然意识到,是不是这个service被mybatis 代理了
,而不是被spring
代理了。
查看配置发现
我配置的mapperscan是全局的,emmm
最后修改配置@MapperScan("com.shuncom.ruler.*.dao.mapper")
成功解决!
关于Invalid bound statement (not found)
,最关键还是没有找到对应的statementId,个人觉得解决方案有以下几个
- 检查
statementId
和xml中的namespace
+id
是否一致- 如果是mybatisplus 则是interface+包名
- 断点查看是否把
.mapper.xml
文件加载读取 - 查看configuration中的加载的statemtn是否是预期。
- 检查xml中是否写错了
- 看网上还有提示说把
mybatis-plus.mapperLocations=classpath:config/mapper/**/*.xml
中的classpath改成classpath*
,但是我当前是没有问题的,我是使用的classpath,可能是版本的问题,我使用classpath是没有问题的- 当前我的版本如下
- mybatis plus是
3.1.0
- mybatis是
3.4.6
- mybatis-spring
2.0.0
- mybatis plus是
- 当前我的版本如下