一、环境

eclipse: Version: 2019-03 (4.11.0)
maven整合mybatis,spring

二、项目结构

Eclipse报错:Invalid bound statement (not found)

三、错误

在maven下,当xml文件与mapper类位于同一目录时运行test命令报错:

Tests in error:

testSelectByid(mapper.UsersMapperTest): Invalid bound statement (not found): mapper.UsersMapper.selectByUname

四、原因

默认源代码目录下的xml等资源文件并不会在编译的时候一块打包进classes文件夹,而是直接舍弃掉。打开maven项目下生成的 target/classes/mapper/ 会发现并没有我们在eclipse中编写好的xml文件
Eclipse报错:Invalid bound statement (not found)

五、解决

1、为达到测试成功的效果,我直接手动将xml文件复制到该目录中,然后在maven中执行test成功,但一旦执行了一次clean,则下次执行test还是会缺少xml文件。
2、一种常见的解决方式是:将xml或properties等配置文件放到resource下,并修改获取配置文件的代码,比如注册mapper.xml的位置等;
Eclipse报错:Invalid bound statement (not found)

相关文章:

  • 2022-12-23
  • 2021-12-25
  • 2021-07-08
  • 2021-04-19
  • 2021-05-03
  • 2021-09-08
  • 2021-04-29
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2021-07-22
  • 2021-06-26
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案