|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package com.java3y.austin.support.utils;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.nacos.api.NacosFactory;
|
|
|
|
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
|
|
|
|
import com.alibaba.nacos.api.exception.NacosException;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
@ -31,16 +33,17 @@ public class NacosUtils {
|
|
|
|
|
private final Properties request = new Properties();
|
|
|
|
|
private final Properties properties = new Properties();
|
|
|
|
|
|
|
|
|
|
public String getProperty(String key) {
|
|
|
|
|
public String getProperty(String key, String defaultValue) {
|
|
|
|
|
try {
|
|
|
|
|
String property = this.getContext();
|
|
|
|
|
if (StringUtils.hasText(property)) {
|
|
|
|
|
properties.load(new StringReader(property));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("Nacos error:{}", e.getMessage());
|
|
|
|
|
log.error("Nacos error:{}", ExceptionUtils.getStackTrace(e));
|
|
|
|
|
}
|
|
|
|
|
return properties.getProperty(key);
|
|
|
|
|
String property = properties.getProperty(key);
|
|
|
|
|
return StrUtil.isBlank(property) ? defaultValue : property;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getContext() {
|
|
|
|
@ -51,7 +54,7 @@ public class NacosUtils {
|
|
|
|
|
context = NacosFactory.createConfigService(request)
|
|
|
|
|
.getConfig(nacosDataId, nacosGroup, 5000);
|
|
|
|
|
} catch (NacosException e) {
|
|
|
|
|
log.error("Nacos error:{}", e.getMessage());
|
|
|
|
|
log.error("Nacos error:{}", ExceptionUtils.getStackTrace(e));
|
|
|
|
|
}
|
|
|
|
|
return context;
|
|
|
|
|
}
|
|
|
|
|