• 启动报错:Caused by: org.apache.ibatis.binding.BindingException汇总解决


    报错

    Springboot启动时从nacos拉取配置。启动报错:

    Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx
    	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227)
    	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49)
    	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
    	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
    	at com.sun.proxy.$Proxy143.selectConfigList(Unknown Source)
    	at com.mmoa.system.service.impl.SysConfigServiceImpl.init(SysConfigServiceImpl.java:37)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
    	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
    	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
    	... 32 common frames omitted
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    报错分析

    通常出现错误Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),都有如下原因

    1.mapper.xml未扫描注册

     # mybatis配置
    mybatis:
        # 搜索指定包别名
        typeAliasesPackage: com.xx.xx
        # 配置mapper的扫描,找到所有的mapper.xml映射文件
        mapperLocations: classpath:mapper/**/*.xml
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2.mapper接口与mapper.xml不在同一个包(package)下或文件名不一致


    3.mapper.xml的命名空间(namespace)与mapper接口的包名不一致


    4. 接口的方法名,与xml中的sql标签的id不一致


    5.接口中的返回值与xml方法配置esultMap或resultType不一致

    通过,排查几种可能得到情况,均为发现问题,由于是通过nacos拉取配置有可能是配置未拉取到。
    仔细查看启动信息。

    15:43:15.030 [main] WARN  c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[application-master.yml] & group[DEFAULT_GROUP]
    15:43:15.037 [main] WARN  c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[test] & group[DEFAULT_GROUP]
    15:43:15.043 [main] WARN  c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[test.yml] & group[DEFAULT_GROUP]
    15:43:15.047 [main] WARN  c.a.c.n.c.NacosPropertySourceBuilder - [loadNacosData,87] - Ignore the empty nacos configuration and get it based on dataId[test-master.yml] & group[DEFAULT_GROUP]
    15:43:15.052 [main] INFO  c.m.s.MmoaSystemApplication - [logStartupProfileInfo,674] - The following profiles are active: master
    
    • 1
    • 2
    • 3
    • 4
    • 5

    发现nacos轮训三个配置都未获取到,猜测正确

    注:
    拉取Nacos的配置文件时会轮训三个dataID:

    格式一:name

    文件名:xxx_config;

    格式二:name.yaml
    文件名+yaml后缀;

    格式三:name-master.yaml
    文件名+profile + 后缀。中间用“-”分割。

    解决

    环境配置错误,修改环境重启服务成功。

    # Spring
    spring: 
      application:
        # 应用名称
        name: test
      profiles:
        # 环境配置
        active: dev
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    小结

    若未改动代码,启动报错,先检查配置环境是否正确或尝试清楚缓存等操作。

    在这里插入图片描述
    我与春风皆过客,你携秋水揽星河。

  • 相关阅读:
    java计算机毕业设计ssm社区养老服务管理系统iq0w7(附源码、数据库)
    [LeetCode]1413. 逐步求和得到正数的最小值
    『第八章』进击的雨燕:Combine 框架
    Opengauss数据类型强转
    浅谈分布式事务及解决方案
    图像相似度识别算法aHash|dHash|PHash
    LeetCode简单题之找到和最大的长度为 K 的子序列
    kafka-consumer-groups.sh消费者组管理
    C++回顾录02
    【直扩通信】直扩通信系统信号捕获性能分析附matlab代码
  • 原文地址:https://blog.csdn.net/qq_35764295/article/details/126228812