wind-zjp

Results 1 comments of wind-zjp

遇到同样的问题。 看了下源码,发现了原因: NacosConfigApplicationContextInitializer.initialize方法向容器中添加了一个name是globalNacosProperties的bean。这个bean表示nacos的全局配置。 ![image](https://user-images.githubusercontent.com/46471406/116768620-80daa480-aa6a-11eb-8531-2b0825632ab5.png) 进去configLoader.buildGlobalNacosProperties()方法,这个全局配置就是nacos.config的配置。 ![image](https://user-images.githubusercontent.com/46471406/116768632-9780fb80-aa6a-11eb-9fc2-9c67741929ee.png) 然后在实例化NamingService时使用的配置是nacos.discovery的配置与全局配置合并的结果 GlobalNacosPropertiesSource.getMergedGlobalProperties方法: ![image](https://user-images.githubusercontent.com/46471406/116768706-3c033d80-aa6b-11eb-985f-69f443f03876.png) currentProperties就是nacos.discovery的配置,globalProperties是全局配置。 合并的逻辑为: ![image](https://user-images.githubusercontent.com/46471406/116768721-5f2ded00-aa6b-11eb-8376-db9a611a1a9d.png) 以全局配置配置为主,如果全局配置没有的才会添加过来。 所以我的解决方法是写一个beanFactoryPostProcessor,获取到全局配置,将全局配置中的属性remove掉. 这样配置合并的结果就是nacos.discovery的配置了。 示例如下:这里因为我们用到了nacos只有命名空间不一样,我只remove了命名空间的属性。 ![image](https://user-images.githubusercontent.com/46471406/116769110-64d80280-aa6c-11eb-8dd9-8506424f2ddc.png)