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:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user