mybatis-plus今天遇到一个问题,就是mybatis 没有读取到mapper.xml 文件。
#实体扫描,多个package用逗号或者分号分隔
mybatis-plus:typeAliasesPackage: com.gblfy.springboot.mybatisplus.entitymapper-locations:- classpath*:com/gblfy/springboot/**/mapping/*.xml
特此记录一下,问题如下:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.husy.mapper.SystemUserMapper.findUserByNameat com.baomidou.mybatisplus.core.override.MybatisMapperMethod$SqlCommand.<init>(MybatisMapperMethod.java:242)at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:54)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedMapperMethod$0(MybatisMapperProxy.java:65)at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.java:65)at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:60)at com.sun.proxy.$Proxy72.findUserByName(Unknown Source)at com.husy.service.impl.SystemUserServiceImpl.findUserByName(SystemUserServiceImpl.java:23)
解决方案1:
添加如下配置即可
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins><resources><resource><directory>src/main/resources</directory><filtering>true</filtering></resource><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource></resources></build>
解决方案2:
把mapping文件夹和文件移动到resources目录下面
#实体扫描,多个package用逗号或者分号分隔
mybatis-plus:typeAliasesPackage: com.gblfy.springboot.mybatisplus.entitymapper-locations:- classpath*:/mapping/*.xml