huaweicloud / spring-cloud-huawei

Spring Cloud Huawei is a framework that makes it easier and productive to develop microservices with Spring Cloud.
https://github.com/huaweicloud/spring-cloud-huawei/wiki
Apache License 2.0
516 stars 221 forks source link

配置中心如何根据key来获取值,因为涉及数组,不能指定参数名获取 #979

Closed WindSearcher closed 1 year ago

WindSearcher commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Sample code:

Expected behavior A clear and concise description of what you expected to happen.

Information

Spring Cloud Huawei version: Spring Cloud version(optional): Spring Boot version(optional): Spring version(optional):

Additional context Add any other context about the problem here.

liubao68 commented 1 year ago

能给一个期望的例子吗?不是很理解

WindSearcher commented 1 year ago

executors: # 动态线程池配置,都有默认值,采用默认值的可以不配置该项,减少配置量

WindSearcher commented 1 year ago

这样的又是如何映射过来,像notifyItems本身是一个数组,官网只有@Value和@RefreshScope

chengyouling commented 1 year ago

试试实现一个config类包含数组对象,监听ConfigurationChangedEvent事件,根据事件里面的key,刷新内容,可以参考:https://github.com/chengyouling/spring-cloud-huawei-samples/blob/master/basic/consumer/src/main/java/com/huaweicloud/samples/consumer/ConfigListen.java

liubao68 commented 1 year ago
  List<XXXModel> models

这种情况spring是可以自动映射的。 在yaml里面可以配置成你给的例子。

还是没太理解你的问题在什么地方。