文章目录

  • ​​1、问题描述​​
  • ​​2、问题原因​​
  • ​​2.1 在application.yml文件中配置mapper-locations​​
  • ​​2.2 在pom.xml文件中指定mapper.xml位置​​

1、问题描述

Property 'mapperLocations' was not specified or no matching resources found

  今天在使用mybatisplus启动项目的时候,控制台输出了如下日志,这是由于xml文件没有被扫描到导致的。

   我的项目结构如下

Property ‘mapperLocations‘ was not specified or no matching resources found_xml文件

我们可以去查看targets目录下面生产的文件,发现并没有xml后缀的文件。

2、问题原因

  springboot项目启动的时候,src/main/java目录里只会扫描.java文件,而我的mapper.xml也是放在这个目录下的,导致它不能被扫描到。所以我们需要指定mapper.xml文件的位置。

2.1 在application.yml文件中配置mapper-locations

mapper-locations: classpath:com/weibo/message/mapper/xml/*.xml

路径根据自己的情况设置,或者为了方便直接写成​​classpath:**/mapper/xml*/*.xml*​

2.2 在pom.xml文件中指定mapper.xml位置

<build>
<resources>
<resource>
<!-- xml放在java目录下-->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<!--指定资源的位置(xml放在resources下,可以不用指定)-->
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>