cxbjava.
2021-08-30 21:33
采纳率: 100%
浏览 1.8k
已结题

Nacos单机版运行时数据库连接异常:No Datasource Set ?

  1. 拉镜像
docker pull caixb/nacos-mysql:5.7.34
docker pull caixb/nacos-server:mysql-5.7
  1. 部署运行
docker run -itd ^
--privileged=true ^
--name mysql-5.7.34  ^
-e MYSQL_ROOT_PASSWORD=root ^
-e MYSQL_DATABASE=nacos_mysql  ^
-e MYSQL_USER=root  ^
-e MYSQL_PASSWORD=root  ^
-v "./mysql:/var/lib/mysql"  ^
--net=nacos-net ^
-p "3306:3306" ^
caixb/nacos-mysql:5.7.34
docker run -itd ^
--name nacos-server-mysql-5.7  ^
--net=nacos-net ^
-p "8848:8848" ^
-p "9848:9848" ^
-e PREFER_HOST_MODE=hostname  ^
-e MODE=standalone  ^
-e SPRING_DATASOURCE_PLATFORM=mysql  ^
-e MYSQL_SERVICE_HOST=mysql-5.7.34 ^
-e MYSQL_SERVICE_DB_NAME=nacos_mysql ^
-e MYSQL_SERVICE_PORT=3306 ^
-e MYSQL_SERVICE_USER=root ^
-e MYSQL_SERVICE_PASSWORD=root ^
-e "MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false"  ^
-v "/standalone-logs/:/home/nacos/logs" ^
-v "/init.d/custom.properties:/home/nacos/init.d/custom.properties"  ^
--link nacos-mysql-5.7 ^
caixb/nacos-server:mysql-5.7

数据库连接正常:

img

但是Nacos docker中控制台报错:

2021-08-30 21:20:18,741 WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memoryMonitor' defined in URL [jar:file:/home/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-config-2.0.3.jar!/com/alibaba/nacos/config/server/monitor/MemoryMonitor.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'asyncNotifyService': Unsatisfied dependency expressed through field 'dumpService'; 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
2021-08-30 21:20:18,827 INFO Nacos Log files: /home/nacos/logs
2021-08-30 21:20:18,827 INFO Nacos Log files: /home/nacos/conf
2021-08-30 21:20:18,828 INFO Nacos Log files: /home/nacos/data
2021-08-30 21:20:18,829 ERROR Startup errors : 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memoryMonitor' defined in URL [jar:file:/home/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-config-2.0.3.jar!/com/alibaba/nacos/config/server/monitor/MemoryMonitor.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'asyncNotifyService': Unsatisfied dependency expressed through field 'dumpService'; 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:769)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
    at com.alibaba.nacos.Nacos.main(Nacos.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
此处省略......

但是nacos能ping通Mysql:

img

望告知!阿里嘎多

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • 有问必答小助手 2021-08-31 11:16
    最佳回答

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


    因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题