1、问题描述

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

​   今天在使用mybatisplus启动项目的时候,控制台输出了如下日志,这是由于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>
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐