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

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>
posted @   别团等shy哥发育  阅读(244)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示