關於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)就可以被識別