nacos-spring-boot-project
nacos-spring-boot-project copied to clipboard
encode配置加载
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
修改内容
- 为
SubNacosProperties增加encode属性属性 - 创建
GlobalNacosProperties和SubNacosProperties时会使用配置文件的里的encode