问题详情:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.coocaa.test.mapper.UserMapper.add
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:43)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
at com.sun.proxy.$Proxy13.add(Unknown Source)
at com.coocaa.test.service.UserService.getUser(UserService.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

源代码: 
userMapper.java

package com.coocaa.test.mapper;

import com.coocaa.test.models.User;

import java.util.List;
public interface UserMapper {
public List<User> findAll(); public void add(User user);
}

userMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//com.coocaa.test.mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.coocaa.test.mapper.UserMapper" >
<resultMap id="baseResultMap" type="com.coocaa.test.models.User">
<result column="u_id" property="uId"/>
<result column="name" property="name"/>
<result column="age" property="age"/>
</resultMap>
<select id="findAll" resultMap="baseResultMap">
SELECT * from user
</select>
<insert id="add" parameterType="com.coocaa.test.models.User" keyProperty="id" useGeneratedKeys="true">
insert user (name,age) values(#{name},#{age})
</insert>
</mapper>

可以看到这两个文件的映射是没有任何问题的,但是为什么会说add方法找不到呢? 
我又去仔细确认了spring配置文件里注册映射文件的的配置,路径好像也是没有问题的

   <!-- 配置myBatis sqlSeesionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations"
value="classpath*:com/coocaa/test/mybatis/*Mapper.xml" />
</bean>

但是实际上是有问题的,项目在构建的时候只会默认的去加载resource资源文件里面的资源,其他地方的不会加载 
 
哈哈,发现问题了吧,target目录下面是没有mybatis目录的。 
这样就有两种解决方法了 
1.将mybatis的xml文件全部放在resource下面 
再修改spring配置文件里面的路径 
2.需要在pom加一个resources的资源加载列表

 <build>
<!--这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。-->
<resources>
<resource>
<!-- 描述存放资源的目录,该路径相对POM路径-->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>

这个时候,再次运行项目,就可以看到target目录下面存在mybatis的xml文件了 
以后如果是要将其他资源文件也放在src目录下面,就需要注意喽,也是需要在pom里面配置的

来源:https://blog.csdn.net/zmj1049933053/article/details/50587109

nvalid bound statement (not found)的更多相关文章

  1. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): da.huying.usermanag ...

  2. Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    主要错误信息如下: HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...

  3. mybatis一个怪异的问题: Invalid bound statement not found

    ssm中报一下错误: invalid bound statement (not found): me.tspace.pm.dao.userdao.getuser    at org.apache.ib ...

  4. 转载:Maven项目mybatis Invalid bound statement (not found)解决方法

    在mapper代理的开发中,程序员需要遵守一些规范,mybatis才能实现mapper接口的代理对象. 它的规范如下: mapper.xml的namespace要写所映射接口的全称类名. mapper ...

  5. mybatis:Invalid bound statement (not found)

    [常规解决办法] 如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因 ...

  6. [mybatis] mybatis错误:Invalid bound statement (not found)

    点击菜单抛出异常: org.springframework.web.util.NestedServletException: Request processing failed; nested exc ...

  7. MyBatis绑定错误[Invalid bound statement (not found)]

    如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...

  8. maven项目:Invalid bound statement

    在使用maven做mybatis项目时会遇到这个问题, org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...

  9. "Invalid bound statement (not found): com.sitech.admin.dao.TbOpenAbilityInfoDao.findAbilityReadyUp"mybatis配置文件bug

    问题描述: 通常在正常启动某项工程后操作某个功能时抛出的bug: org.apache.ibatis.binding.BindingException: Invalid bound statement ...

随机推荐

  1. js日期操作,某天的N天后,一个月后的日期

    var date = new Date(); var tomorrow = date.setDate(new Date().getDate() + 10); //10天后的日期 console.log ...

  2. vue-router路由的使用

    1.路由作用 用vue.js + vue-router创建单页面应用.页面不需要刷新就可以页面跳转,提供用户更好体验. 2.路由配置 new Router({ routes: [{ path: '/' ...

  3. SQL SERVER 数据库被标记为“可疑”的解决办法

    问题背景: 日常对Sql Server 2005关系数据库进行操作时,有时对数据库(如:Sharepoint网站配置数据库名Sharepoint_Config)进行些不正常操作如数据库在读写时而无故停 ...

  4. WPF 控件事件的一个小坑…

    最近想判断一下 Slider 是由鼠标点击而改变值,还是由程序内部代码改变的值,发现鼠标的各种事件比如 MouseDown.MouseUp.MouseLeftButtonDown 什么的,都没有任何反 ...

  5. eclipse CDT写c++使用文件作为输入源(输入重定向)

    在main函数第一句添加下面. freopen("inputfile","r",stdin); 创建一个inputfile,放project根文件夹下. 注意添 ...

  6. 学习排序算法(一):单文档方法 Pointwise

    学习排序算法(一):单文档方法 Pointwise 1. 基本思想 这样的方法主要是将搜索结果的文档变为特征向量,然后将排序问题转化成了机器学习中的常规的分类问题,并且是个多类分类问题. 2. 方法流 ...

  7. ios Coredata 关联 UITableView 数据自动更新

    昨天写了一篇关于coredata的文章,自己觉得挺傻的文章.没想其它程序员看过后觉得更傻,于是今天决定写一篇厉害点的,首先写了一个coredata和uitableview结合的框架,非常简单实现了数据 ...

  8. IOS 学习 Key-value coding

    1 前言 本节我们主要介绍键值编码,以及如何使一个类符合KVC编码. 2 详述 键-值编码是一个对于间接访问一个对象属性和关系使用字符标识的机制.它支持或者关系几个特别的Cocoa编程机制和技术,在C ...

  9. iOS求职之C语言面试题

    1.static有什么用途?(请至少说明两种) 1)限制变量的作用域 2)设置变量的存储域(堆,主动分配内存也是堆) 1)在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变.
 2)  ...

  10. what-is-a-closure

    https://stackoverflow.com/questions/36636/what-is-a-closure https://www.quora.com/What-are-upvalues- ...