[alibaba/nacos]YmlChangeParser中的buildFlattenedMap方法抛出ClassCastException异常

2025-10-31 222 views
1

Describe the bug 当我使用AbstractConfigChangeListener进行配置监听时,有配置变更了,将会调用YmlChangeParser中的doParse方法来将新旧配置转换为map并筛选出被修改的配置返回以修改的配置,在进行getFlattenedMap方法时,抛出了ClassCastException(java.lang.Integer cannot be cast to java.lang.String)异常,造成这个的原因是因为我的yml配置中,有一个int类型,比如 When I use AbstractConfigChangeListener for configuration listening, there is a configuration change, and the doParse method in YmlChangeParser will be called to convert the old and new configurations to map and filter out the modified configurations back to the modified configurations, when the getFlattenedMap method is performed. I threw the ClassCastException (java.lang.Integer cannot be cast to java.lang.String) exception, and the reason for this is because my yml configuration has an int type, such as

nacos中的配置: Configuration in nacos: kd: 100:FFLANCNALSD

回答

6

Please assign to me

2

@wangyuewen-china will solve it

4

一般来说 key 为 int 类型 的场景还是比较少吧

0

先讨论看看有没有处理的必要

8

先讨论看看有没有处理的必要

好的

3

一般来说 key 为 int 类型 的场景还是比较少吧

这种情况是属于自定义的配置,因为对接的快递100的接口,所以定义的配置就为 kd.100.key=thekey kd.100.sign=thesign 这种情况

7

这种情况,请使用AbstractListener 监听整个配置,然后自己进行yaml解析,由于此时回调的是完整的yaml配置, 只要您自己的yaml解析能正常处理就可以。

3

这种情况,请使用 监听整个配置,然后自己进行yaml解析,由于此时回调的是完整的yaml配置, 只要您自己的yaml解析能正常处理就可以。AbstractListener

可是这样的话,我需要自己重新实现一份新旧配置解析和对比的逻辑,有点多此一举了。 其实只需要在getFlattenedMap 的getKey时使用String.valueOf()转换为String就可以了

0

我认为这种场景属于自定义的特殊场景, 需要以定制化的方式处理。