nacos-spring-boot-project icon indicating copy to clipboard operation
nacos-spring-boot-project copied to clipboard

encode配置加载

Open ShipinZ opened this issue 1 year ago • 1 comments

bug描述:

之前配置文件中的encode属性不会被加载到GlobalNacosProperties,导致当加载全局配置时创建的ConfigService的cacheKey不包含encode属性 CacheableEventPublishingNacosServiceFactory.ConfigCreateWorker

        public ConfigService run(Properties properties, ConfigService service) throws NacosException {
           // 当通过全局配置配置创建时,这里的cacheKey不包含encode
            String cacheKey = NacosUtils.identify(properties);
            ConfigService configService = (ConfigService)CacheableEventPublishingNacosServiceFactory.this.configServicesCache.get(cacheKey);
            if (configService == null) {
                if (service == null) {
                    service = NacosFactory.createConfigService(properties);
                }

                configService = new EventPublishingConfigService(service, properties, CacheableEventPublishingNacosServiceFactory.getSingleton().context, CacheableEventPublishingNacosServiceFactory.getSingleton().nacosConfigListenerExecutor);
                CacheableEventPublishingNacosServiceFactory.this.configServicesCache.put(cacheKey, configService);
            }

            return (ConfigService)configService;
        }

但是注解@NacosConfigurationProperties加载的默认配置,又会默认包含encodeUTF-8,所以这导致同一个服务的cacheKey不一致会创建两次ConfigService

修改内容

  1. SubNacosProperties增加encode属性属性
  2. 创建GlobalNacosPropertiesSubNacosProperties时会使用配置文件的里的encode

ShipinZ avatar Sep 12 '24 06:09 ShipinZ

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 12 '24 06:09 CLAassistant