You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "Aithosa (via GitHub)" <gi...@apache.org> on 2025/02/10 18:08:33 UTC

[I] 关于动态配置读取 [servicecomb-java-chassis]

Aithosa opened a new issue, #4714:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4714

   我注意到`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<String, Object> 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` 都读不到变化。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] 关于动态配置读取 [servicecomb-java-chassis]

Posted by "Aithosa (via GitHub)" <gi...@apache.org>.
Aithosa commented on issue #4714:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4714#issuecomment-2649741847

   我链接配置中心试了下在上面修改配置可以动态读取了。
   不过`DynamicProperties`不能像archaius一样读取配置中心以外配置文件的变化吗?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] 关于动态配置读取 [servicecomb-java-chassis]

Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4714:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4714#issuecomment-2650644041

   你参考配置中心的扩展或者DEMO的示例代码,写一个监听配置文件变化的source即可。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] 关于动态配置读取 [servicecomb-java-chassis]

Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4714:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4714#issuecomment-2649616089

   你连接配置中心就可以了。测试代码是经过特殊处理的,新增了一个基于内存的配置中心。 
   
   删除archaius等组件主要原因是这些组件停止维护和演进了,影响未来演进,用了新的方式替换,参考: https://servicecomb.apache.org/references/java-chassis/zh_CN/introduce3.x.x.html 。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org