'Property 'mapperLocations' was not specified.
时间: 2025-06-07 18:06:59 浏览: 20
### 解决 `Property 'mapperLocations' was not specified` 错误
当遇到 `Property 'mapperLocations' was not specified or no matching resources found` 的错误时,通常是因为 MyBatis Plus 未能找到映射器 XML 文件。这可能是由于配置不正确或路径设置有误。
#### 配置 `application.yml`
确保在 `application.yml` 中正确指定了 `mapper-locations` 属性。该属性用于告诉 MyBatis Plus 去哪里查找映射器 XML 文件。以下是正确的配置方式:
```yaml
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: false
mapper-locations: classpath*:/com/**/mapper/*.xml
type-aliases-package: com.example.bean
```
注意这里的 `classpath*:` 是为了确保能够加载多个 JAR 包中的资源文件[^4]。
#### Maven 打包配置
如果项目是基于 Maven 构建的,则需要确保打包过程中不会遗漏这些 XML 资源文件。可以在 `pom.xml` 中添加如下配置来保证资源被正确包含:
```xml
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.yml</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
```
此外,在多模块项目中特别需要注意这一点,因为默认情况下只有当前模块内的资源会被打包进去。
通过以上方法可以有效解决因 `mapperLocations` 未指定而导致的问题。请检查并调整相应配置后再尝试重新启动应用程序。
阅读全文
相关推荐















