apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.13k stars 10.2k forks source link

客户端设置了namespaces不起作用 #2841

Closed nangergong closed 4 years ago

nangergong commented 4 years ago

Describe the bug

我用springboot,在application.yml中有如下配置

apollo:
  bootstrap:
    enabled: true
    eagerLoad:
      enabled: true
    namespaces: config.yml
app:
  id: user

启动程序后, 报错如下,我发现这个连接“http://149.218.9.160:9180/configs/user/default/application?ip=192.168.2.212” 中app.id取了上面的配置,但是namespace没有取用config.yml,而是总是用application,我改了app.id和namespaces实验多次,发现就是app.id有效,namespaces无效,请问如何解决这个问题?

` 2019-12-13 13:19:10.545 WARN 9320 --- [ main] c.c.f.a.i.AbstractConfigRepository : Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository, reason: Load Apollo Config failed - appId: didi, cluster: default, namespace: application, url: http://149.218.9.160:9180/configs/user/default/application?ip=192.168.2.212 [Cause: [status code: 404] Could not find config for namespace - appId: user, cluster: default, namespace: application, please check whether the configs are released in Apollo!]

`

nobodyiam commented 4 years ago

这个日志是说加载不到application这个namespace,并不是说没有加载config.yml这个namespace。

看下代码中应该是指定了加载application了,比如@EnableApolloConfig@ApolloConfigChangeListener默认是加载application的。

nangergong commented 4 years ago

这个日志是说加载不到application这个namespace,并不是说没有加载config.yml这个namespace。

看下代码中应该是指定了加载application了,比如@EnableApolloConfig@ApolloConfigChangeListener默认是加载application的。

不能在配置文件制定加载其他namespace吗?不能的话这个apollo.bootstrap.namespaces有啥用?

nobodyiam commented 4 years ago

可以指定,我前面的回答不是说apollo没加载config.yml,而是说从日志上可以判断你在别的地方指定了加载application

lsxu commented 4 years ago

我也有这个问题 apollo.bootstrap.namespaces 无论怎么指定 最后还是只加载 application

lsxu commented 4 years ago

请问这个问题您解决了么 @nangergong

liquanjin commented 4 years ago

我也遇到类似的问题。 一个工程关联多个namespace,配置如下:

apollo.bootstrap.namespaces=application.yml,baseconfig

对应 app.id 下也存在对应namespace 。application.yml 为私有的,baseconfig 为public的。

apollo 版本: server:1.3.0 client :1.3.0

对应log如下:

2020-03-13 17:00:18.068  WARN [cas-**,] Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository, reason: Load Apollo Config failed - appId: cas-**, cluster: default, namespace: application.yml,baseconfig, url: http://10.1.41.129:8091/configs/cas-**/default/application.yml,baseconfig?ip=172.22.0.4 [Cause: [status code: 404] Could not find config for namespace - appId: cas-**, cluster: default, namespace: application.yml,baseconfig, please check whether the configs are released in Apollo!]
nobodyiam commented 4 years ago

@liquanjin 是不是逗号写成中文了?看这个日志是没有把namespace列表拆分出来

https://github.com/ctripcorp/apollo/blob/0769c80f661d82af3f0b53802fb25dc77f7d09a8/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java#L100

liquanjin commented 4 years ago

@nobodyiam 有的有的。之前调试的时候,就看到了。 符号是英文的 只是不影响运行,所以也没太在意。但是一直 print warn 还是很烦

apollo 版本: server:1.3.0 client :1.3.0

liquanjin commented 4 years ago

@nobodyiam initialize 方法中的 List namespaceList 的分割是正确的✅

nobodyiam commented 4 years ago

这个不应该啊,是否能上传一个最简的demo可以复现该问题的?

liquanjin commented 4 years ago

好的。我这两天加一个demo复现一下

liquanjin commented 4 years ago

感谢 顺哥。问题已经定位,不是apollo的问题。导致问题的原因应该是集成nexpion-disovery 后,配置方式不合理导致。

liquanjin commented 4 years ago

不过顺哥,我还是要请教一句。 1、每个工程必须要有一个默认的application namesapces 吗? 现在WARN 提示的场景 就是对应project 没有 application namesapces,然后就会一直 WARN。。 2、另外,如果通过 apollo.bootstrap.enabled=true 配置 namespace后,是不是就不用 @EnableApolloConfig 注解了 ?

apollo.bootstrap.enabled=true
apollo.bootstrap.eagerLoad.enabled=true
apollo.bootstrap.namespaces=application.yml,baseconfig
nobodyiam commented 4 years ago

1、每个工程必须要有一个默认的application namesapces 吗? 不是,如果报WARN的话,说明代码中有配置过加载application namespace,比如不带参数的@EnableApolloConfig,不带参数的@ConfigChangeListener

  1. 另外,如果通过 apollo.bootstrap.enabled=true 配置 namespace后,是不是就不用 @EnableApolloConfig 注解了 ? 是的,就不用@EnableApolloConfig了
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in 14 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed because it has not had activity in the last 14 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.

shenxianwei commented 2 years ago

试下@EnableApolloConfig(value = {"你的自定义命名空间"})