alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.91k stars 8.32k forks source link

spring-cloud-starter-alibaba-nacos-config:shared-configs共享配置同应用配置在同一group下,且无法读取公共配置;The shared configuration is in the same group as the application configuration, and the public configuration cannot be read. #3594

Closed Jiehoom closed 9 months ago

Jiehoom commented 9 months ago

Describe the bug

Java应用中需要抽离出公共配置,使用shared-configs 共享配置设置同一命名空间存在的group下时,提示java.lang.IllegalArgumentException: Value must only contain valid chars,更换不存在的组后,异常消失,但无法读取到公共配置

Java applications need to extract the public configuration, using shared-configs shared-configs set the same namespace exists under the group, prompted java.lang.IllegalArgumentException: Value must only contain valid chars, replace the non-existent IllegalArgumentException: Value must only contain valid chars. After replacing the non-existing group, the exception disappears, but the public configuration cannot be read.

Expected behavior

期望在同一命名空间和组下获取公共配置的功能,并且能够读取到公共配置

Expect the ability to get public configuration under the same namespace and group and be able to read the public configuration

Actually behavior

不能获取同一命名空间同一分组下的公共配置,并且没有认证是否shared-configs默认是同一命名空间。修改不存在的分组后,不再提示IllegalArgumentException异常,但是读取不到公共配置。

Cannot get public configurations under the same grouping in the same namespace, and there is no authentication if shared-configs is the same namespace by default. After modifying a non-existing grouping, the IllegalArgumentException is no longer thrown, but the public configuration cannot be read.

How to Reproduce

Steps to reproduce the behavior:

  1. Setting shared-configs.group to be the same as config.group The bootstrap.yml information is as follows:
    
    server:
    port: 8080

Spring

spring: application:

应用名称

name: cbas-gateway

profiles:

环境配置

active: test

cloud: nacos: discovery:

服务注册地址

    server-addr: 127.0.0.1:8848
    # 服务注册命名空间
    namespace: cbas_test
    # 服务注册所属组
    group: cbas_test
    # 服务注册用户名
    username: nacos
    # 服务注册用户密码
    password: nacos
  config:
    # 配置中心地址
    server-addr: 127.0.0.1:8848
    # 配置中心命名空间
    namespace: cbas_test
    # 配置中心所属组
    group: cbas_test
    # 配置中心用户名
    username: nacos
    # 配置中心用户密码
    password: nacos
    # 配置文件格式
    file-extension: yml
    # 共享配置
    shared-configs:
      - data-id: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
        group: ${spring.cloud.nacos.config.group}

2. Add public config into Same Namespace
<img width="1420" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/bd21d67e-ade1-4ca1-a6fc-89b454bbcbd7">

3. Run the Application

### **Desktop (please complete the following information):**
 - OS: [Mac OS 14.2.1 Win10]
 - Version [nacos-server 2.2.0 run in docker , nacos-client 2.2.0]
 - Module [naming/config]
 - SDK [spring-cloud-starter-alibaba-nacos-config]

### **ERROR Snapshot:**

1. Same NameSpace and exist group setting:
<img width="895" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/f7aa61b4-608b-4573-bc3a-2b83c628b959">

Error message:
<img width="1216" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/cadc3897-74e8-4bfd-b8bc-9e93d1b98b86">

2. Same Namespace but not exist group setting:

<img width="954" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/a9e79694-3ec7-4ac6-af3f-dc573d5a3731">

<img width="1106" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/847bda1e-6a4b-4c45-9346-e84366d69cd3">

Error message:
<img width="1620" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/b9f0e84e-1149-4c0e-b82e-e57f0c00af97">

No redis configuration is read:
<img width="1800" alt="image" src="https://github.com/alibaba/spring-cloud-alibaba/assets/67527509/ac2f23d3-be99-45c5-ba49-f7824e4edc98">

Looking forward to your reply
yuluo-yx commented 9 months ago

方便提供一个复现的最小 demo,不是很好复现

Jiehoom commented 9 months ago

方便提供一个复现的最小 demo,不是很好复现

现在问题是解决了,因为共享配置中参数写错了。但是有个疑问,我有过将nacos停止,nacos停止后却还是提示错误。这是什么原因呢

Jiehoom commented 9 months ago

方便提供一个复现的最小 demo,不是很好复现

现在问题是解决了,因为共享配置中参数写错了。但是有个疑问,我有过将nacos停止,nacos停止后却还是提示错误。这是什么原因呢

方便提供一个复现的最小 demo,不是很好复现 主要的问题是共享配置中写错了一个配置,之前的配置如下 :

暴露监控端点

management: endpoints: web: exposure: include: *

yuluo-yx commented 9 months ago

方便提供一个复现的最小 demo,不是很好复现

现在问题是解决了,因为共享配置中参数写错了。但是有个疑问,我有过将nacos停止,nacos停止后却还是提示错误。这是什么原因呢

没有很理解表达的意思 🤔

Jiehoom commented 9 months ago

我把nacos服务停止了,然后跟上述问题一样的配置,启动应用后还是提示异常出错。我理解nacos服务停止了后应该是读取不到nacos公共配置的,就不应该报错。

On Thu, Jan 18, 2024 at 17:02 YuLuo @.***> wrote:

方便提供一个复现的最小 demo,不是很好复现

现在问题是解决了,因为共享配置中参数写错了。但是有个疑问,我有过将nacos停止,nacos停止后却还是提示错误。这是什么原因呢

没有很理解表达的意思 🤔

— Reply to this email directly, view it on GitHub https://github.com/alibaba/spring-cloud-alibaba/issues/3594#issuecomment-1898063213, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQDGGVPOQLKZL2U3IYCNNTLYPDQJZAVCNFSM6AAAAABB4EZGY2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJYGA3DGMRRGM . You are receiving this because you modified the open/close state.Message ID: @.***>

ruansheng8 commented 9 months ago

@Jiehoom Nacos 客户端自身有个配置容灾机制,如果获取配置成功时,会将配置内容保存一份到本地快照文件中,当 Nacos 服务不可用时,会从本地快照文件中加载,该机制主要为了容灾用的。

如果想关闭该机制,可以调用 SnapShotSwitch#setIsSnapShot 方法进行关闭

Jiehoom commented 9 months ago

@Jiehoom Nacos 客户端自身有个配置容灾机制,如果获取配置成功时,会将配置内容保存一份到本地快照文件中,当 Nacos 服务不可用时,会从本地快照文件中加载,该机制主要为了容灾用的。

如果想关闭该机制,可以调用 SnapShotSwitch#setIsSnapShot 方法进行关闭

非常感谢🙏