Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

关于动态配置读取

未关闭
#4,714 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
java, spring
领域
backend

调研方向

首先将 DynamicPropertiesImpl 和 DynamicProperties.getStringProperty 与 ProviderController 示例进行比较,然后跟踪 Environment 的更改是如何传播的,以及 EventManager 如何发布 ConfigurationChangedEvent。使用 BMI 示例重现该行为,并记录所需的配置,或找出缺失的更新路径,以便 dynamicProperties 和 environment 都能反映已更改的值。

由索引模型根据 Issue 内容生成。

描述

我注意到3.x版本把原本完全使用archaius API读取配置的部分全部换掉了,在DynamicPropertiesImpl中通过Environment来读取配置,这是为什么,为了更接入Spring原生的操作吗?

然后我按照文档在程序中读取配置信息试了下,使用dynamicProperties.getStringProperty()无法读到配置的变化,然后我看了下[servicecomb-java-chassis](https://github.com/apache/servicecomb-java-chassis)的测试:

    HashMap<String, Object> updated = new HashMap<>();
    updated.put(stringPropertyName, newValue);
    EventManager.post(ConfigurationChangedEvent.createIncremental(updated));

运行没有问题,但是按照文档那样以非mock的方式测试就读不到配置的变化,请问是有什么遗漏的额外配置吗?

我测试时用的是基于开发第一个微服务应用里 bmi 那个示例改写的。

@RestSchema(schemaId = "ProviderController")
@RequestMapping(path = "/provider")
public class ProviderController {
    private DynamicProperties dynamicProperties;

    @Autowired
    private Environment environment;

    private String example;

    @Autowired
    public ProviderController(DynamicProperties dynamicProperties) {
        this.dynamicProperties = dynamicProperties;
        // 在构造函数中注册回调,这样配置变化时会自动更新 example 值
        this.example = this.dynamicProperties.getStringProperty("basic.example",
                value -> {
                    System.out.println("Configuration changed, new value: " + value);
                    this.example = value;
                }, "not set");
    }

    @GetMapping(path = "/example")
    public String getExampleValue() {
        String dynamicValue = dynamicProperties.getStringProperty("basic.example", "not set");
        String envValue = environment.getProperty("basic.example", "not set");
        System.out.println("Dynamic value: " + dynamicValue);
        System.out.println("Environment value: " + envValue);
        return example;
    }
}

不管是用 dynamicProperties 还是 environment 都读不到变化。

主要语言
Java
星标
1.9k
派生
813
平均合并
8 天 23 小时
30 天内合并 PR
1

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/servicecomb-java-chassis 的其他 Issue

查看 apache/servicecomb-java-chassis 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。