org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
2017-04-21 14:27
561 查看
第二次遇见这个问题了,上次就是倒腾很久,这次高低得记录下,加深印象!
绑定失败的原因不止一个,有可能是namespace配置的不是mapper接口,或者你的mapper接口中的方法名和mapper.xml中statement的id不对应,还有就是mapper.xml没有加载进来,不外乎这几种吧。我遇到的bug就是mapper.xml没有加载进来,但是又没有报错找不到文件,而是绑定失败,我是反复检查配置文件,生怕哪里对应不上,后来google才发现,idea有一个问题,就是你的xml文件如果不放在webroot下,是不会把该文件输出到target下的,而项目中的mapper.xml文件和mapper接口是放在一起的,在src目录下,所以加载不到绑定失败。
我用的是扫描的方式加载mapper的xml文件
在pom.xml文件中加入以下配置
然后在target的classess下就看到src目录的xml文件了
绑定失败的问题就解决啦
绑定失败的原因不止一个,有可能是namespace配置的不是mapper接口,或者你的mapper接口中的方法名和mapper.xml中statement的id不对应,还有就是mapper.xml没有加载进来,不外乎这几种吧。我遇到的bug就是mapper.xml没有加载进来,但是又没有报错找不到文件,而是绑定失败,我是反复检查配置文件,生怕哪里对应不上,后来google才发现,idea有一个问题,就是你的xml文件如果不放在webroot下,是不会把该文件输出到target下的,而项目中的mapper.xml文件和mapper接口是放在一起的,在src目录下,所以加载不到绑定失败。
我用的是扫描的方式加载mapper的xml文件
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.ky.mapper" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean>
在pom.xml文件中加入以下配置
<build> <finalName>javaWeb</finalName> <!--这段配置解决了无法将src目录下的配置文件打包进输出目录--> <resources> <resource> <directory>src/main/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> </build>
然后在target的classess下就看到src目录的xml文件了
绑定失败的问题就解决啦
相关文章推荐
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.coder520.mamabike.user.dao.UserMapper.selectByPrimaryKey
- IDEA的maven项目出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误解决方法
- maven打包项目后org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Mybatis笔记二:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 关于mybatis的org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 解决过程
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- mybatis的org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- 出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)的解决方法
- 配置文件出错 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- mybatis绑定错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- mybatis使用bug:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- mybaits错误记录:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):