解决异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

在前一段时间遇到了一个异常: BindingException ,无效的绑定语句。

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.practicecode.wxy.mybatis.service.TbCustomerService.getBaseMapper

我已经在启动类中添加了 @MapperScan 注解,在找了很长时间的原因与测试下发现,mapper层调用API都是好使的,只有service接口调用的方法都报异常,后来才发现该注解下的包路径没有写对:

// 错误示范
@MapperScan("com.example.practicecode.wxy.mybatis")
// 正确的写法
@MapperScan("com.example.practicecode.wxy.mybatis.mapper")

笔者当时误认为mapper层包括在mybatis包下直接写就可以,没想到犯了这么低级的错误。

除却上面的错误方式还有一种也会造成上面的绑定异常,当 src/main/java 此路径下的mapper包与 src/main/resources 此路径下的mapper.xml路径或名称不一致时也会返回异常信息。

小提示: 顺便记录一下近日遇到的一个异常:

代码如下:

@SpringBootTest
@RequiredArgsConstructor
class PracticeCodeApplicationTests {
    private final StudentMapper studentMapper;
    @Test
    public void myTest(){
        Student student = studentMapper.selectStudentById(1);
        System.out.println(student);
    }
}

异常如下:

org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [final com.example.practicecode.wxy.mybatis.mapper.StudentMapper studentMapper] in constructor [public com.example.practicecode.PracticeCodeApplicationTests(com.example.practicecode.wxy.mybatis.mapper.StudentMapper)].

此异常是因为我在测试类中使用了@RequiredArgsConstructor这个注解,去掉使用 @Autowired 即可。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值