通过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目录,就可以修复这个问题

虽千万人,吾往矣!
目录
相关文章
|
21天前
|
Java Maven
SpringBoot项目的用maven插件打包报Test错误
SpringBoot项目的用maven插件打包报Test错误
|
13天前
|
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
22 1
|
22天前
|
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
191 0
|
7月前
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
|
8月前
|
XML Java 数据库连接
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
123 0
|
10月前
|
XML 前端开发 Java
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)异常
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)异常
1032 0
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)异常
|
12月前
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
90 0
|
19天前
|
Java Apache Maven
Maven 项目文档
在C:/MVN下,使用命令`mvn archetype:generate -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false`创建Maven Java项目。确保`pom.xml`包含`maven-site-plugin`和`maven-project-info-reports-plugin`配置,版本分别至少为3.3和2.7,以避免`NoClassDefFoundError`。
|
18天前
|
Java Maven
Maven 构建 Java 项目
使用 Maven 的 archetype:generate 命令创建 Java 项目,如 `mvn archetype:generate` -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false,在 C:\MVN 下生成基于 maven 的 consumerBanking 项目。
|
6天前
|
Java Apache Maven
Maven 项目文档
在C:/MVN下,使用`mvn archetype:generate`命令创建`consumerBanking`项目,设置相关参数。确保`pom.xml`包含`maven-site-plugin`和`maven-project-info-reports-plugin`,版本至少为3.3和2.7,以避免`NoClassDefFoundError`。升级`maven-site-plugin`至3.3+解决该错误。

推荐镜像

更多