[alibaba/nacos]重启应用偶尔出现报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

2025-10-30 178 views
7

重启应用偶尔出现报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured 报错后重新启动就好了,不是必现,但是出现的很频繁。 nacos:2.1.0 SpringCloudAlibaba:2.2.9 MySQL:8.0.28 配置:

spring:
  application:
    name: supplier-service
  cloud:
    nacos:
      config:
        server-addr: ${nacos.server-addr}
        username: ${nacos.username}
        password: ${nacos.password}
        namespace: dev
        extension-configs:
          - data-id: mysql-db-config.yml
            group: DEFAULT_GROUP
          - data-id: redis-config.yml
            group: DEFAULT_GROUP
          - data-id: oauth2-config.yml
            group: DEFAULT_GROUP
            refresh: true
nacos:
  server-addr: juru.nacos-dev.jrmall.cn:90
  username: nacos
  password: nacos

错误日志如下:

2023-07-20 19:50:54.816 [enterprise-service] [main] INFO  c.a.d.s.b.a.DruidDataSourceAutoConfigure - [] Init DruidDataSource
2023-07-20 19:50:55.390 [enterprise-service] [main] INFO  org.apache.catalina.core.StandardService - [] Stopping service [Tomcat]
2023-07-20 19:50:55.563 [enterprise-service] [main] ERROR o.s.b.diagnostics.LoggingFailureAnalysisReporter - [] 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (the profiles prod are currently active).

回答

1

和nacos关系不大, 大概率是应用自己的问题。

看下是否启动顺序有问题,在获取远端配置前就加载数据库连接 看下config.log, 是否获取到了配置中心的配置。 是否应用在使用配置时有问题,取了空的配置内容作为初始化的值。
1

和nacos关系不大, 大概率是应用自己的问题。

看下是否启动顺序有问题,在获取远端配置前就加载数据库连接 看下config.log, 是否获取到了配置中心的配置。 是否应用在使用配置时有问题,取了空的配置内容作为初始化的值。

之前的日志发的不全,首先是加载第一个配置的时候403了,之后才报了上面的错误

 :: Spring Boot ::       (v2.3.12.RELEASE)

2023-07-28 17:06:25.075 [material-service] [main] ERROR c.a.cloud.nacos.client.NacosPropertySourceBuilder - [] get data from Nacos error,dataId:mysql-db-config.yml 
com.alibaba.nacos.api.exception.NacosException: http error, code=403,msg=user not found!,dataId=mysql-db-config.yml,group=DEFAULT_GROUP,tenant=dev
    at com.alibaba.nacos.client.config.impl.ClientWorker$ConfigRpcTransportClient.queryConfig(ClientWorker.java:979)
    at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:396)
    at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:166)
    at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:94)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:73)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:202)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:189)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosConfiguration(NacosPropertySourceLocator.java:163)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadExtConfiguration(NacosPropertySourceLocator.java:128)
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:102)
    at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:52)
    at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:47)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:98)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:623)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:367)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236)
    at com.jrmall.mat.MaterialServiceApplication.main(MaterialServiceApplication.java:18)
2023-07-28 17:06:25.512 [material-service] [main] DEBUG o.springframework.boot.env.OriginTrackedYamlLoader - [] Loading from YAML: Byte array resource [redis-config.yml]
4

数据库错误

2023-07-28 17:06:40.722 [material-service] [com.alibaba.nacos.client.remote.worker] INFO  com.alibaba.nacos.common.remote.client - [] [f5223fd0-2551-48bd-949e-273032765869_config-0] Notify connected event to listeners.
2023-07-28 17:06:40.722 [material-service] [com.alibaba.nacos.client.remote.worker] INFO  com.alibaba.nacos.client.config.impl.ClientWorker - [] [f5223fd0-2551-48bd-949e-273032765869_config-0] Connected,notify listen context...
2023-07-28 17:06:40.797 [material-service] [main] INFO  c.a.d.s.b.a.DruidDataSourceAutoConfigure - [] Init DruidDataSource
2023-07-28 17:06:40.907 [material-service] [main] INFO  org.apache.catalina.core.StandardService - [] Stopping service [Tomcat]
2023-07-28 17:06:40.981 [material-service] [main] ERROR o.s.b.diagnostics.LoggingFailureAnalysisReporter - [] 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).
9

code=403,msg=user not found!,

用户名密码不对,或者用户不存在

7

code=403,msg=user not found!,

用户名密码不对,或者用户不存在

重新启动一下就好了

1

可以更新下客户端版本,观察下是否有优化