alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.36k stars 12.86k forks source link

Liunx & docker & IDEA debugging - error [No DataSource set] #10412

Closed Timzer closed 1 year ago

Timzer commented 1 year ago

Describe the bug Nacos using external data source - error [No DataSource set] reported

Nacos使用外部数据源-报错[No DataSource set]


2023-04-29 17:57:23.880 ERROR 31056 --- [           main] c.a.n.c.l.StartingApplicationListener    : Startup errors : 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'communicationController' defined in file [C:\code\learn\nacos-2.1.1\config\target\classes\com\alibaba\nacos\config\server\controller\CommunicationController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalDumpService': Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure : No DataSource set at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420) at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) at com.alibaba.nacos.Nacos.main(Nacos.java:35) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalDumpService': Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure : No DataSource set at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ... 19 common frames omitted Caused by: com.alibaba.nacos.api.exception.NacosException: Nacos Server did not start because dumpservice bean construction failure : No DataSource set at com.alibaba.nacos.config.server.service.dump.DumpService.dumpOperate(DumpService.java:225) at com.alibaba.nacos.config.server.service.dump.ExternalDumpService.init(ExternalDumpService.java:52) 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: java.lang.IllegalStateException: No DataSource set at org.springframework.util.Assert.state(Assert.java:76) at org.springframework.jdbc.support.JdbcAccessor.obtainDataSource(JdbcAccessor.java:86) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:376) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:465) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:475) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:508) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:515) at com.alibaba.nacos.config.server.service.repository.extrnal.ExternalStoragePersistServiceImpl.findConfigMaxId(ExternalStoragePersistServiceImpl.java:674) at com.alibaba.nacos.config.server.service.dump.processor.DumpAllProcessor.process(DumpAllProcessor.java:51) at com.alibaba.nacos.config.server.service.dump.DumpService.dumpConfigInfo(DumpService.java:282) at com.alibaba.nacos.config.server.service.dump.DumpService.dumpOperate(DumpService.java:195) ... 40 common frames omitted



# Background
Our company (financial industry) is preparing to follow up on a large scale, using nacos as a registration center.
> 本公司准备后续大规模,使用nacos做为注册中心。

# Error message
## Version & Environment
1. nacos2.1.1 version, singleton mode
2. mysql version 5.7 and 8.0 have been tried
3. Liunx & docker & IDEA debug both report this error
> 版本&环境
> 1. nacos2.1.1版本、单例模式
> 2. mysql版本5.7和8.0都尝试过
> 3. Liunx & docker & IDEA调试都报这个错误

![image](https://user-images.githubusercontent.com/25809905/235300875-b7a272b6-b864-49ff-b049-bc0ccbda262b.png)

# Debug debugging

## Error location
1. system initialization, it will look for the maximum id in config_info table, due to the call to JdbcTemplate when dataSource=null causes the system error
ExternalStoragePersistServiceImpl.findConfigMaxId()
> 报错定位
> 1. 系统初始化,会查找config_info表中的最大id,由于调用JdbcTemplate的时候dataSource=null导致系统报错

![image](https://user-images.githubusercontent.com/25809905/235300896-8057c767-9f62-4212-b686-6973796e89e2.png)
![image](https://user-images.githubusercontent.com/25809905/235300904-219e95bf-1f3d-481f-bd19-1a4589e0d629.png)
![image](https://user-images.githubusercontent.com/25809905/235300907-d372be46-66f1-4b81-8dbd-261d81e431b8.png)

## Cause tracing
2. getDynamicDataSource.
DynamicDataSource.getDataSource()
3. reload the configuration information of the dynamic data source
ExternalDataSourceServiceImpl().reload()
> 原因追溯
> 2. 获取动态数据源,
> 3. 动态数据源重新加载配置信息

Currently unable to determine the exact cause, the parameters are changed only in application.properties. Please help me to solve
> 目前无法判断,具体原因,参数改动只在application.properties中。请各位大佬支招,解决

我可以提供远程环境,或者复现方法
Timzer commented 1 year ago

@xuechaos @loadchange @KomachiSion @shiyiyue1102 @karsonto 各位大佬支招,这个是我的配置或者环境有问题,还是要怎么解决

Daydreamer-ia commented 1 year ago

数据库连接的url里面,nacos_config参数检查是不是和你mysql的数据库名对得上。或者其他原因导致数据库连接失败,都会出现No datasource set

Timzer commented 1 year ago

数据库连接的url里面,nacos_config参数检查是不是和你mysql的数据库名对得上。或者其他原因导致数据库连接失败,都会出现No datasource set

url是跟官方提供的一致,第一次用是ok的,后面重启了一下,就报这个错误了

db.url.0=jdbc:mysql://node29:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
KomachiSion commented 1 year ago

那就是数据库连不通了, 可以看下其他日志文件, 看下具体连接数据库失败的原因。