1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

fix(nacos): fix issue #859

This commit is contained in:
chuntaojun
2019-09-12 20:20:02 +08:00
parent d2684c2882
commit 5162d02b4e
3 changed files with 32 additions and 97 deletions

View File

@@ -17,52 +17,25 @@
package com.alibaba.cloud.nacos;
import com.alibaba.nacos.api.config.ConfigService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Objects;
/**
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
*/
public class NacosConfigManager implements ApplicationContextAware {
public class NacosConfigManager {
@Autowired
private NacosConfigProperties properties;
private static ConfigService service = null;
public ConfigService getConfigService() {
return ServiceHolder.getInstance().getService();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
NacosConfigProperties properties = applicationContext
.getBean(NacosConfigProperties.class);
ServiceHolder holder = ServiceHolder.getInstance();
if (!holder.alreadyInit) {
ServiceHolder.getInstance().setService(properties.configServiceInstance());
}
}
static class ServiceHolder {
private ConfigService service = null;
private boolean alreadyInit = false;
private static final ServiceHolder holder = new ServiceHolder();
ServiceHolder() {
}
static ServiceHolder getInstance() {
return holder;
}
void setService(ConfigService service) {
alreadyInit = true;
this.service = service;
}
ConfigService getService() {
return service;
if (Objects.isNull(service)) {
service = properties.configServiceInstance();
}
return service;
}
}