一、问题描述
环境:springcloud + mybatis-plus
访问查询列表的接口时,报错如下:
ERROR |http-nio-8888-exec-9 |GlobalExceptionHandler.java:22 |com.xxx.xxx.service.base.handler.GlobalExceptionHandler |Invalid bound statement (not found): com.xxx.xxx.service.xxx.mapper.XxxMapper.selectBypIds
二、原因
dao层编译后只有class文件,没有mapper.xml,
因为maven工程在默认情况下src/main/java目录下的所有资源文件是不发布到target目录下的
三、解决
1、在对应的项目的pom.xml中配置:
这样项目在打包时就会将java目录中的*.xml文件也进行打包
<build>
<!-- 项目打包 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
检查:在pom.xml中进行上述配置后,重新打包项目,看看target目录下是否成功出现了xml文件夹。
2、然后在配置文件application.yml中配置:
mybatis-plus:
#配置到xml的包名,告诉框架xml的位置
mapper-locations: classpath:com/xxx/xxx/service/xxx/mapper/xml/*.xml