org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.xx.mapper.XX.xxx

本文介绍了一种常见问题的解决方案,即在Spring Boot项目中,Mapper XML文件未能编译到target目录的问题。通过在pom.xml的build标签中添加资源配置,指向Mapper XML文件的位置,确保它们被正确编译。尽管application.properties已配置mybatis.mapper-locations,但此额外步骤仍为必要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目访问接口报错:

排查发现mapper文件没有编译进target,mapper目录下只有class文件没有mapper.xml:

解决方法:在build标签中使用<resources>标签指向mapper.xml文件位置

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>

重新编译,问题解决。不过仍然存在的疑问是之前在application.properties文件中已经配置了属性mybatis.mapper-locations来指向mapper.xml的文件目录,不知道为什么还要再pom中添加resource标签

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值