解决报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu

导读:本篇文章讲解 解决报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

一.问题描述

spring项目中,使用mybatis编写xml以后,项目启动报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu.service.mapper.EduCourseMapper.

解决报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu

 

 二.问题分析

先说结论,此处报错的原因是maven默认情况下,只会将java文件进行编译打包,此处mybatis的mapper.xml文件没有加载进targer目录,无法读取,自然启动不了,如图

mapper包下有mapper.xml文件 :

解决报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu

而编译后,targer包下并没有xml文件:

解决报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu

 

三.解决方法

这里,我们有多种解决方法,最简单的就是把xml文件复制到target对应的包下,但是不建议这么做,因此我们有两种一劳永逸的解决方案:

第一种:

在springboot的配置文件中编写

  #配置mapper xml文件的路径
#  mapper-locations: classpath:com/atguigu/service/mapper/xml/*.xml

如果解决不了,就用下面一种

第二种:

在maven的pom.xml中编写静态资源过滤

    <!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<!--    <build>-->
<!--        <resources>-->
<!--            <resource>-->
<!--                <directory>src/main/resources</directory>-->
<!--            </resource>-->
<!--            <resource>-->
<!--                <directory>src/main/java</directory>-->
<!--                <includes>-->
<!--                    <include>**/*.xml</include>-->
<!--                </includes>-->
<!--                <filtering>false</filtering>-->
<!--            </resource>-->
<!--        </resources>-->
<!--    </build>-->

如果有什么不明白的,欢迎在评论区评论哦,!

如果以上方案解决了你的问题,请给博主点个赞吧~

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/116132.html

(0)
Java光头强的头像Java光头强

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!