apache / apache/servicecomb-java-chassis
关于动态配置读取
- 主要言語
- Java
- スター
- 1.9k
- フォーク
- 814
- 平均マージ
- 8日 23時間
- マージ済み PR(30日)
- 1
説明
我注意到`3.x`版本把原本完全使用`archaius API`读取配置的部分全部换掉了,在`DynamicPropertiesImpl`中通过`Environment`来读取配置,这是为什么,为了更接入Spring原生的操作吗?
然后我按照文档[在程序中读取配置信息](https://servicecomb.apache.org/references/java-chassis/zh_CN/config/read-config.html)试了下,使用`dynamicProperties.getStringProperty()`无法读到配置的变化,然后我看了下`[servicecomb-java-chassis](https://github.com/apache/servicecomb-java-chassis)`的测试:
```java
HashMap updated = new HashMap<>();
updated.put(stringPropertyName, newValue);
EventManager.post(ConfigurationChangedEvent.createIncremental(updated));
```
运行没有问题,但是按照文档那样以非mock的方式测试就读不到配置的变化,请问是有什么遗漏的额外配置吗?
我测试时用的是基于[开发第一个微服务应用](https://servicecomb.apache.org/references/java-chassis/zh_CN/start/first-sample.html)里 `bmi` 那个示例改写的。
```Java
@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` 都读不到变化。
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず DynamicPropertiesImpl と DynamicProperties.getStringProperty を ProviderController の例と比較し、次に Environment の変更がどのように伝播され、EventManager がどのように ConfigurationChangedEvent をポストするかを追跡します。BMI のサンプルで動作を再現し、必要な設定を文書化するか、dynamicProperties と environment の両方に変更された値が反映されるために欠けている更新経路を特定します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java, spring
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100