天天看点

Nacos Ignore the empty nacos configuration and get it based on dataId

1.配置错误  dataId问题

启动日志:

使用properties格式的文件:

Ignore the empty nacos configuration and get it based on dataId[xxx-server] & group[DEFAULT_GROUP]
Ignore the empty nacos configuration and get it based on dataId[xxx-server.properties] & group[DEFAULT_GROUP]
Ignore the empty nacos configuration and get it based on dataId[xxx-server-dev.properties] & group[DEFAULT_GROUP]
           

使用yaml文件格式:

Ignore the empty nacos configuration and get it based on dataId[xxx-server] & group[DEFAULT_GROUP]
Ignore the empty nacos configuration and get it based on dataId[xxx-server.yaml] & group[DEFAULT_GROUP]
Ignore the empty nacos configuration and get it based on dataId[xxx-server-dev.yaml] & group[DEFAULT_GROUP]
           

官方介绍:

在 Nacos Spring Cloud 中,

dataId

 的完整格式如下:

${prefix}-${spring.profiles.active}.${file-extension}
           
  • prefix

     默认为 

    spring.application.name

     的值,也可以通过配置项 

    spring.cloud.nacos.config.prefix

    来配置。
  • spring.profiles.active

     即为当前环境对应的 profile,详情可以参考 Spring Boot文档。 注意:当 

    spring.profiles.active

     为空时,对应的连接符 

    -

     也将不存在,dataId 的拼接格式变成 

    ${prefix}.${file-extension}

  • file-exetension

     为配置内容的数据格式,可以通过配置项 

    spring.cloud.nacos.config.file-extension

     来配置。目前只支持 

    properties

     和 

    yaml

     类型。

踩坑:之前习惯yaml配置文件使用yml后缀,因此在nacos服务器配置时,仍然使用yml。这个错误的!!!

Nacos Ignore the empty nacos configuration and get it based on dataId

 第二种问题:

        配置了namespace和group。 如果配置了namespace,需要在配置文件中指定具体的namespace,例如:

Nacos Ignore the empty nacos configuration and get it based on dataId

上面新增了namespace和group后,发现找不到配置文件。

我们需要钱nacos服务器上进行相关的配置。

Nacos Ignore the empty nacos configuration and get it based on dataId

我这里未指定命名空间ID.(其实项目中配置文件,namespace的值是空间ID,不是空间名称)

自动生成:

Nacos Ignore the empty nacos configuration and get it based on dataId

 文件配置:

Nacos Ignore the empty nacos configuration and get it based on dataId

 继续启动服务,发现仍然报错。

原因是namespce未使用命名空间ID,修改后,再启动:

Nacos Ignore the empty nacos configuration and get it based on dataId
Nacos Ignore the empty nacos configuration and get it based on dataId

因为是轮询,匹配到第三个,项目启动成功!!