报错
Springboot启动时从nacos拉取配置。启动报错:
Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxxat 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
报错分析
通常出现错误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
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
发现nacos轮训三个配置都未获取到,猜测正确
注:
拉取Nacos的配置文件时会轮训三个dataID:
格式一:name
文件名:xxx_config;
格式二:name.yaml
文件名+yaml后缀;
格式三:name-master.yaml
文件名+profile + 后缀。中间用“-”分割。
解决
环境配置错误,修改环境重启服务成功。
# Springspring: application:# 应用名称name: testprofiles:# 环境配置active: dev
小结
若未改动代码,启动报错,先检查配置环境是否正确或尝试清楚缓存等操作。
我与春风皆过客,你携秋水揽星河。