关于IDEA 只要用*mapper.xml 项目加载报错:org.apache.ibatis.binding.BindingException: Invalid bound statement异常

关于IDEA 只要用*mapper.xml 项目加载报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.itheima.s**.mapper.ItemMapper.selectByExample 加载不到Mybatis的那个*mapper.xml文件的解决方案:


pom.xml文件中配置一下才能正常使用mapper.xml


配置如下

配置如下:
 <build> 
<resources> 
<resource> 
<directory>src/main/java</directory> 
<includes> 
<include>**/*.properties</include> 
<include>**/*.xml</include> 
</includes> 
<filtering>false</filtering> 
</resource> 
</resources> 
</build> 

总结:

根本原因是IDEA自身机制问题(对classpath的规定)。

Eclipse把资源文件(问题中的xml放在src文件夹下,可以在classpath下找到

但是在IDEA中,直接把资源文件放在src文件夹下,如果不进行设置,是不能被找到的。

解决办法就如下:

1)直接将资源文件放到它认定的resources目录下

2)配置build插件,(作用其实就是通过插件把资源文件复制到resources目录)

不管Eclipse还是IDEA最终保证xml文件在classpath下(classes)就可以被识别



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章