IDEA 解决src/main/java目录下mapper.xml文件不被扫描的问题

 

 如图所示,将mapper接口与xml放在Java目录下,经编译后也确实是这样(能正确扫描的结果)。

 

可能出现的问题

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

这是因为spring没有找到xml文件的位置导致的

一种办法是将xml文件放入resource目录下可以解决

另一种就是如我那样将mapper和xml都放在Java目录下的解决如下(在当前项目的pom文件添加如下代码)

 1  2 <build>
 3         <resources>
 4             <resource>
 5                 <directory>src/main/java</directory>
 6                 <includes>
 7                     <include>**/*.xml</include>
 8                 </includes>
 9             </resource>
10         </resources>
11     </build>

此时spring会将src/main/java这个目录也认为时资源目录,会到里面去找到相应的xml文件

在web模块的配置文件了配置mybatis即可

 1 mybatis:

2   mapper-locations: classpath*:com/fengzi/bms/mapper/*.xml 

 

我也是初学者,本文是学习中的笔记,如有不对尽情指出,互相学习,谢谢。


 

posted @ 2020-08-09 14:48  偷时间的贼ing  阅读(1421)  评论(0)    收藏  举报