`
daoshud1
  • 浏览: 550306 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (

    博客分类:
  • BUG
 
阅读更多
关于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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics