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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?