通过maven test 报org.apache.ibatis.binding.BindingException: Invalid bound statement

简介: 背景 直接使用eclipse工具去执行,没有问题,通过testng.xml去执行,没有问题,但通过mvn clean test执行,就报错,提示org.apache.ibatis.binding.BindingException: Invalid bound statement 解决方法 首先先肯定的是:mybatis的配置是没有问题,因为eclipse可以正常执行; 在eclipse中把mapper的xml文件放到src代码目录下是可以一起打包进classes的,而maven去编译的时候不会,就会导致找不到xml报错。

背景

直接使用eclipse工具去执行,没有问题,通过testng.xml去执行,没有问题,但通过mvn clean test执行,就报错,提示org.apache.ibatis.binding.BindingException: Invalid bound statement

解决方法

首先先肯定的是:mybatis的配置是没有问题,因为eclipse可以正常执行;

在eclipse中把mapper的xml文件放到src代码目录下是可以一起打包进classes的,而maven去编译的时候不会,就会导致找不到xml报错。

 

    • 第一种,由于idea默认是不打包src中的xml文件,所以在eclipse中你可以把xml放到src中没有问题,但是在idea中,你把mapper的xml文件放到resources资源中就可以正常访问!
      这种的话由于代码调整比较大,不建议这样修改;

    • 第二种 在maven配置maven对资源文件的访问,具体做法:在pom中,build节点中加入

      <resources>
           <resource>
               <directory>src/main/resources</directory>
               <includes>
                   <include>** /*.properties</include>
                   <include>**/ *.xml</include>
               </includes>
               <filtering> true </filtering>
           </resource>
           <resource>
               <directory>src/main/java</directory>
               <includes>
                   <include>** /*.properties</include>
                   <include>**/ *.xml</include>
               </includes>
               <filtering> true </filtering>
           </resource>
      </resources>

      maven在build的时候可以指定resources目录,就可以修复这个问题

虽千万人,吾往矣!
目录
相关文章
|
2月前
|
Java Maven
SpringBoot项目的用maven插件打包报Test错误
SpringBoot项目的用maven插件打包报Test错误
|
3天前
|
Java 数据库连接 mybatis
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
|
1月前
|
XML Java 数据库连接
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):XXXXX
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):XXXXX
|
2月前
|
XML Java 数据库连接
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
31 1
|
27天前
|
Java Maven
蓝易云 - Maven使用mvn命令时跳过test的参数
另外,还有一个参数 `-Dmaven.test.skip=true`也可以用来跳过测试,但是这个参数不仅跳过测试,还会跳过编译测试代码的阶段。所以,如果你的项目中有其他模块依赖测试代码,那么使用 `-Dmaven.test.skip=true`可能会导致构建失败。在大多数情况下,推荐使用 `-DskipTests`参数。
10 0
|
2月前
|
Java Maven
Maven打包出错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test
Maven打包出错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test
290 0
|
8月前
org.apache.ibatis.builder.BuilderException: An invalid property ‘jdbcType ‘ was found in mapping
org.apache.ibatis.builder.BuilderException: An invalid property ‘jdbcType ‘ was found in mapping
|
9月前
|
XML Java 数据库连接
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
126 0
|
10天前
|
Java Maven
Maven如何创建Maven web项目
Maven如何创建Maven web项目
|
13天前
|
Java Apache Maven
Maven 项目文档
使用Maven创建`consumerBanking`项目,执行`mvn archetype:generate`命令初始化。确保`pom.xml`包含`maven-site-plugin`至少版本3.3和`maven-project-info-reports-plugin`至少版本2.7,以避免NoClassDefFoundError。升级插件解决文档构建问题。