Invalid bound statement (not found)

mybatis-plus Invalid bound statement (not found)

最近把maven项目变成了多模块的项目模块如下db类的都在dao层下

image-20200320110031750

发现报错信息Invalid bound statement (not found),而且出现注入接口的时候

@Component
public class ModelConverterReceiver {
	@Autowired
	private MessageProcess process;
}

提示

image-20200320112258135

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代理了 这里很关键

image-20200320111157867

继续断点

com.baomidou.mybatisplus.core.override.MybatisMapperMethod.SqlCommand#SqlCommand

image-20200320111835902

发现configuration中mappedStatements中不为空,说明mybatis解析了我的xml文件,配置是没有问题的,继续断点

com.baomidou.mybatisplus.core.override.MybatisMapperMethod.SqlCommand#resolveMappedStatement

image-20200320112019947

发现当前statementid不正确,不应该是service的对应方法。

沉默许久,结合之前的问题,突然意识到,是不是这个service被mybatis 代理了,而不是被spring代理了。

查看配置发现

image-20200320112139699

我配置的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-spring2.0.0
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值