Spring Boot整合Mybatis时报错:无效的绑定语句(未找到):com.xxxx.springbootmybatis.mapper.Userxmlmapper.selcetAll

本次使用的Springboot来整合Mybatis去调用数据库进行操作,发现按照以往的Mybatis常规操作,遇到了一些问题。

在使用注解时,能够完美运行。

在使用xml时,按照以往的com.xxx.mapper进行接口和xml的书写发现出现了问题。

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rachel.springbootmybatis.mapper.Userxmlmapper.selectAll

首先在Target目录下进行了排查

发现xml文件是存在的。

另外又对mapper常出的问题进行了排查,具体如下:

  1.  Mapper.接口名称和Mapper.xml是否一致
  2. Mapper接口中的方法是否在Mapper.xml中均被实现
  3. Mapper.xml中的namespace是否为Mapper接口的应用路径
  4. application.propertis或application.yml配置mybatis.type-aliases-package配置实体路径是否正确
  5. application.propertis或application.yml配置mybatis.mapper-locations是否正确
  6. springboot入口程序中是否有添加@MapperScan(“com.xx.xx.xx.xx.dao.mapper”)注解,路径是否到mapper的包名

发现均没有问题,再看yaml文件的配置

#datasoure
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/springboot
    username: root
    password: 527113
    driver-class-name: com.mysql.cj.jdbc.Driver


#mybatis
mybatis:
  #mapper映射

  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.rachel.springbootmybatis.domain.User
  #配置Type路径
#mybatis-config配置

 发现也没什么问题。

结果是发现在pom配置中出了问题。在pom中加上如下配置就OK了

<resources>
          <resource>
               <directory>src/main/java</directory>
               <includes>
                   <include>**/*.xml</include>
               </includes>
               <filtering>false</filtering>
           </resource>
</resources>

问题得到解决。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值