---
title: "关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement ("
author: "daoshud1"
date: "2016-09-25T22:11:51Z"
tags: []
categories: ["编程语言"]
slug: "mybatis-org-apache-ibatis-binding-bindingexception-invalid-bound-statement"
draft: false
lastmod: "2016-09-25T22:11:51Z"
id: 2326732
url: "https://daoshud1.iteye.com/blog/2326732"
---

关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。 最近从eclipse转到intellij idea，确实比eclipse好用太多，但是也是各种不熟悉，导致了很多问题，本来搭好的maven+ssm框架在eclipse上能用，迁移到idea中是各种问题，一一解决之后就剩下这个问题。org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) : org.dao.UserDao.selectByPrimaryKey,意思是我的mapper和dao的映射和接口绑定有问题。 \[img]http://dl2.iteye.com/upload/attachment/0120/2337/ce98581f-b342-3571-a160-f3b31b8eee51.jpeg\[/img] 我的spring和mybatis整合配置如下： \[code="java"] classpath\*:com/leadthing/pojo/mapping/\*Mapper.xml \[/code] 但我的mapper和dao中是一一对应的，所以我的问题不在这儿。 Junit测试一直是红色的一条，这个问题让我头疼，网上看了很多资料最后发现是intellij idea的问题，在eclipse中把mapper的xml文件放到src代码目录下是可以一起打包进classes的，而在新版intellij idea中是不会一起打包，就会导致找不到xml报错。 首先确保xml中的namespace配置是你的接口全类名，而不是包名！ 确认dao接口中的方法，和xml中一一对应，返回类型，参数都正确。 解决方法 第一种，由于idea默认是不打包src中的xml文件，所以在eclipse中你可以把xml放到src中没有问题，但是在idea中，你把mapper的xml文件放到resources资源中就可以正常访问！ 第二种 在maven配置maven对资源文件的访问，具体做法：在pom中，build节点中加入 \[code="java"] src/man/resources \*\*/\*.properties \*\*/\*.xml true src/main/java \*\*/\*.properties \*\*/\*.xml true \[/code] 总结 以上两种方法个人在intellij idea中亲测成功。 Junit测试通过。看着那一条变成绿色，log4j日志打印成功，整个人都轻松了。 原文\[url]http://blog.csdn.net/oppo5630/article/details/51351578\[/url]