服务启动的时候,加载不到配置数据, 但是我的配置信息跟视频一样
来源:12-2 使用Nacos管理配置

qcnuo_
2020-08-13
server:
port: 8081
spring:
profiles:
active: dev
application:
# 服务名称
name: test-server
cloud:
nacos:
config:
# nacos 配置中心
server-addr: 127.0.0.1:8848
group: DEV_GROUP
prefix: test-nacos-config
file-extension: yml
nacos 文件 test-server-dev.yml
[INFO ][2020-08-13 18:16:17.214][main][c.a.n.client.config.impl.LocalConfigInfoProcessor:195] -> LOCAL_SNAPSHOT_PATH:/Users/qcnuo/nacos/config
[INFO ][2020-08-13 18:16:17.240][main][com.alibaba.nacos.client.config.impl.Limiter:53] -> limitTime:5.0
[WARN ][2020-08-13 18:16:17.275][main][c.a.cloud.nacos.client.NacosPropertySourceBuilder:87] -> Ignore the empty nacos configuration and get it based on dataId[test-server] & group[DEFAULT_GROUP]
[WARN ][2020-08-13 18:16:17.280][main][c.a.cloud.nacos.client.NacosPropertySourceBuilder:87] -> Ignore the empty nacos configuration and get it based on dataId[test-server.yml] & group[DEFAULT_GROUP]
[WARN ][2020-08-13 18:16:17.283][main][c.a.cloud.nacos.client.NacosPropertySourceBuilder:87] -> Ignore the empty nacos configuration and get it based on dataId[test-server-dev.yml] & group[DEFAULT_GROUP]
[INFO ][2020-08-13 18:16:17.284][main][o.s.c.b.c.PropertySourceBootstrapConfiguration:105] -> Located property source: [BootstrapPropertySource {name='bootstrapProperties-test-server-dev.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-test-server.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-test-server,DEFAULT_GROUP'}]
[INFO ][2020-08-13 18:16:17.288][main][com.ntan.test.TestServiceApplication:655] -> The following profiles are active: dev
[WARN ][2020-08-13 18:16:18.050][main][o.springframework.boot.actuate.endpoint.EndpointId:155] -> Endpoint ID 'nacos-config' contains invalid characters, please migrate to a valid format.
[WARN ][2020-08-13 18:16:18.053][main][o.springframework.boot.actuate.endpoint.EndpointId:155] -> Endpoint ID 'nacos-discovery' contains invalid characters, please migrate to a valid format.
[WARN ][2020-08-13 18:16:18.291][main][o.springframework.boot.actuate.endpoint.EndpointId:155] -> Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
[INFO ][2020-08-13 18:16:18.428][main][o.springframework.cloud.context.scope.GenericScope:295] -> BeanFactory id=32d4a495-473e-3dc9-8756-5abfb4d47938
[INFO ][2020-08-13 18:16:18.763][main][o.s.boot.web.embedded.tomcat.TomcatWebServer:92] -> Tomcat initialized with port(s): 8081 (http)
[INFO ][2020-08-13 18:16:18.772][main][org.apache.coyote.http11.Http11NioProtocol:173] -> Initializing ProtocolHandler ["http-nio-8081"]
[INFO ][2020-08-13 18:16:18.773][main][org.apache.catalina.core.StandardService:173] -> Starting service [Tomcat]
[INFO ][2020-08-13 18:16:18.773][main][org.apache.catalina.core.StandardEngine:173] -> Starting Servlet engine: [Apache Tomcat/9.0.31]
[INFO ][2020-08-13 18:16:18.922][main][o.a.c.core.ContainerBase.[Tomcat].[localhost].[/]:173] -> Initializing Spring embedded WebApplicationContext
[INFO ][2020-08-13 18:16:18.923][main][org.springframework.web.context.ContextLoader:284] -> Root WebApplicationContext: initialization completed in 1615 ms
[INFO ][2020-08-13 18:16:19.087][main][com.alibaba.nacos.client.naming:56] -> initializer namespace from System Property :null
[INFO ][2020-08-13 18:16:19.088][main][com.alibaba.nacos.client.naming:65] -> initializer namespace from System Environment :null
[INFO ][2020-08-13 18:16:19.089][main][com.alibaba.nacos.client.naming:75] -> initializer namespace from System Property :null
[WARN ][2020-08-13 18:16:19.298][main][o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:558] -> Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'ntantest' in value "${ntantest}"
[INFO ][2020-08-13 18:16:19.301][main][org.apache.catalina.core.StandardService:173] -> Stopping service [Tomcat]
[WARN ][2020-08-13 18:16:19.305][main][org.apache.catalina.loader.WebappClassLoaderBase:173] -> The web application [ROOT] appears to have started a thread named [com.alibaba.nacos.naming.client.listener] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
写回答
3回答
-
qq_忙狗_0
2020-12-07
文件名称改成test-server-dev.yaml试一下
00 -
慕勒3270337
2020-11-24
我的问题也是一样,content-center出现这样的问题,但是同样代码再user-center中可以正常得到Nacos配置的your.configuration
00 -
大目
2020-08-13
您好,重点日志:
[WARN ][2020-08-13 18:16:17.275][main][c.a.cloud.nacos.client.NacosPropertySourceBuilder:87] -> Ignore the empty nacos configuration and get it based on dataId[test-server] & group[DEFAULT_GROUP] [WARN ][2020-08-13 18:16:17.280][main][c.a.cloud.nacos.client.NacosPropertySourceBuilder:87] -> Ignore the empty nacos configuration and get it based on dataId[test-server.yml] & group[DEFAULT_GROUP] [WARN ][2020-08-13 18:16:17.283][main][c.a.cloud.nacos.client.NacosPropertySourceBuilder:87] -> Ignore the empty nacos configuration and get it based on dataId[test-server-dev.yml] & group[DEFAULT_GROUP] [INFO ][2020-08-13 18:16:17.284][main][o.s.c.b.c.PropertySourceBootstrapConfiguration:105] -> Located property source: [BootstrapPropertySource {name='bootstrapProperties-test-server-dev.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-test-server.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-test-server,DEFAULT_GROUP'}]
由日志可知,它忽略了WARN这三行的dataId,去尝试读取第四行的dataId。
group: DEV_GROUP prefix: test-nacos-config
话说你这种配置方式,应该在DEV_GROUP下创建一个名为test-nacos-config-dev.yml。相关的代码在:com.alibaba.cloud.nacos.client.NacosPropertySourceLocator#loadApplicationConfiguration
或者,可以直接把这两行配置删除,其他不改,这样会自动读取 test-server-dev.yml
00
相似问题