---
title: "org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):"
author: "larryscale"
date: "2016-09-09T00:01:22Z"
tags: []
categories: ["编程语言"]
slug: "org-apache-ibatis-binding-bindingexception-invalid-bound-statement-not-found"
draft: false
lastmod: "2016-09-09T00:01:22Z"
id: 2323448
url: "https://itsaga.iteye.com/blog/2323448"
---

```
   idea下Maven项目（Spring+Mybatis） 查询时报错：org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)，解决方案：
 
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): spring.security.maven.dao.T_userMapper.selectByUserName
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.$Proxy22.selectByUserName(Unknown Source)
at spring.security.maven.serviceImp.UserServiceImp.selectByUserName(UserServiceImp.java:20)
at TestUser.getUser(TestUser.java:17)
 
 
原因：
问题解决了，不是代码问题是编译器问题，当然也也许是可以配置的
我用的是intellij idea ，创建的是maven项目。maven的结构就不多了其中java是放置源码的resource是资源文件的，那么按照我们的以前学习mybatis的方法是建议把Mapper.xml的文件放在daomain里面和实体在一起的，淡然这不是一定的路径写对了，爱放哪里原则上没问题的 。可是idea明确了源码和资源文件的放置位置（maven项目），也就是说源码就要会呗编译，当我把xml文件放在java目录下的daomian我再猜想是不是被编译了，才导致找不到方法，于是我把Mapper的映射文件放到资源文件下，改下加载Mpper.xml的路径，结果可以了。问题解决了。其实之前我有一次也是这样解决的，可是我当时不以为然，因为我们一贯是放在daomian下面的。
 
解决方法：
如果是Intellij idea的话，需要在pom.xml文件中加入， 会将src/main/java下的
xml文件随同java编译后的class文件一同copy到相应的class目录：
<build>
    <resources>
         <resource>
             <directory>src/main/java</directory>
             <includes>
                 <include>**/*.xml</include>
             </includes>
         </resource>
    </resources>
</build>
 


解决方式2：
IDEA中，如果你把xml文件放在java目录下，编译和打包时是不会打包进WEB-INF/classes下的，需要在pom文件中配置：
```

&lt;build&gt;

`<!--mybatis逆向工程生成代码-->`

`<plugins>`

`<plugin>`

`<groupId>org.mybatis.generator</groupId>`

`<artifactId>mybatis-generator-maven-plugin</artifactId>`

`<version>${mybatis_general.version}</version>`

`</plugin>`

`<plugin>`

`<artifactId>maven-compiler-plugin</artifactId>`

`<configuration>`

`<source>1.7</source>`

`<target>1.7</target>`

`</configuration>`

`</plugin>`

`</plugins>`

`<!--打包时包含源代码包下的资源文件-->`

`<resources>`

`<resource>`

`<directory>src/main/java</directory>`

`<includes>`

`<include>**/*.properties</include>`

`<include>**/*.xml</include>`

`</includes>`

`<filtering>false</filtering>`

`</resource>`

`</resources>`  

&lt;/build&gt;