关于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的映射和接口绑定有问题。
我的spring和mybatis整合配置如下:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations">
<list>
<value>classpath*:com/leadthing/pojo/mapping/*Mapper.xml</value>
</list>
</property>
</bean>
但我的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节点中加入
<resources>
<resource>
<directory>src/man/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>
总结
以上两种方法个人在intellij idea中亲测成功。
Junit测试通过。看着那一条变成绿色,log4j日志打印成功,整个人都轻松了。
原文
http://blog.csdn.net/oppo5630/article/details/51351578
- 大小: 65.5 KB
分享到:
相关推荐
出现以上的情况主要的原因是因为在主配置文件标签没正确的指向映射接口的配置文件。 解决方案:1.检查的name是否正确,如我的name属性填的就是com.it.dao 2、检查的class属性或resource属性,我resource这里写的是...
搭建mybatis所需包org.apache.ibatis.annotations.Param @Param
主要介绍了Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法的相关资料,需要的朋友可以参考下
org.apache.ibatis.logging org.apache.ibatis.logging.commons org.apache.ibatis.logging.jdbc org.apache.ibatis.logging.jdk14 org.apache.ibatis.logging.log4j org.apache.ibatis.logging.log4j2 org.apache....
个人博客系统(SpringBoot+Mybatis).zip个人博客系统(SpringBoot+Mybatis).zip个人博客系统(SpringBoot+Mybatis).zip个人博客系统(SpringBoot+Mybatis).zip个人博客系统(SpringBoot+Mybatis).zip个人博客...
中秋博饼游戏(Swing+Spring+MyBatis).zip中秋博饼游戏(Swing+Spring+MyBatis).zip 中秋博饼游戏(Swing+Spring+MyBatis).zip中秋博饼游戏(Swing+Spring+MyBatis).zip 中秋博饼游戏(Swing+Spring+MyBatis).zip中秋博饼...
eclipse mybatis.generator.eclipse.site- 插件eclipse mybatis.generator.eclipse.site- 插件
简易的中秋博饼游戏(Swing+Spring+MyBatis).zip 简易的中秋博饼游戏(Swing+Spring+MyBatis).zip 简易的中秋博饼游戏(Swing+Spring+MyBatis).zip 简易的中秋博饼游戏(Swing+Spring+MyBatis).zip 简易的中秋博饼游戏...
│ │ │ frame-sourcefiles-org.apache.ibatis.binding.html │ │ │ frame-sourcefiles-org.apache.ibatis.builder.annotation.html │ │ │ frame-sourcefiles-org.apache.ibatis.builder.html │ │ │ frame-...
org.mybatis.generator.core_1.3.1.201101032122.jar
NULL 博文链接:https://wangjiankui1989.iteye.com/blog/1141198
Caused By: org.apache.ibatis.builder.BuilderException: Could not find SQL statement to include with refid 'SAD02.SAD02_COL' at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler....
>Window->prefenrence->XML->XML Catalog->User Specifiled Entreis->Add->Location(此处是你放dtd文件的位置例如:D:\mybatis\mybatis-3-config.dtd)->Key(如果更改config,此处应该是:-//mybatis.org//DTD ...
mybatis 代码生成器插件mybatis
myBatis3.2.2.jar
mybatisGenerator.rar mybatis自动生成
springboot mybatis mapper.xml 配置,里面包含了新增,修改,删除,查询,分页查询例子以及通过 网页访问的例子
mybatis 3.x源码深度解析与最佳实践.html
主要介绍了MyBatis绑定错误提示BindingException:Invalid bound statement (not found)的解决办法,非常不错,具有参考借鉴价值,需要的的朋友参考下吧