最近自己搭建springboot项目整合mybatis-plus,利用代码生成器生成的xml文件位于mapper/xml包下,启动项目时老是报Property 'mapperLocations' was not specified,大意是mapperLocations属性未指定,运行时报如下错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
包结构如下:

解决方案
mybatis-plus: mapper-locations: classpath:com/jc/**/*.xml
同时pom文件的build添加如下信息
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**.*</include>
</includes>
</resource>
</resources>
</build>
本文介绍了一种常见的SpringBoot项目中使用MyBatis-Plus时遇到的问题,即XML映射文件未能被正确加载导致的错误,并提供了解决方案。包括配置正确的mapper-locations路径以及在pom.xml中设置资源文件加载规则。
411

被折叠的 条评论
为什么被折叠?



