Commit f2c18352 by Nepxion

Nacos配置支持客户自定义

parent 5b397658
......@@ -21,8 +21,8 @@
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -11,7 +11,9 @@ package com.nepxion.discovery.common.nacos.configuration;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
......@@ -28,11 +30,21 @@ public class NacosAutoConfiguration {
private Environment environment;
@Bean
@ConditionalOnMissingBean
public ConfigService configService() throws NacosException {
String url = environment.getProperty(NacosConstant.URL);
Properties properties = new Properties();
properties.put(NacosConstant.URL_KEY, url);
String url = environment.getProperty(NacosConstant.URL);
if (StringUtils.isNotEmpty(url)) {
properties.put(NacosConstant.SERVER_ADDR, url);
} else {
throw new IllegalArgumentException("Url can't be null or empty");
}
String namespace = environment.getProperty(NacosConstant.NAMESPACE);
if (StringUtils.isNotEmpty(namespace)) {
properties.put(NacosConstant.NAMESPACE, namespace);
}
return NacosFactory.createConfigService(properties);
}
......
......@@ -9,10 +9,12 @@ package com.nepxion.discovery.common.nacos.constant;
* @version 1.0
*/
public class NacosConstant {
public static final String URL_KEY = "serverAddr";
import com.alibaba.nacos.api.PropertyKeyConst;
public class NacosConstant extends PropertyKeyConst {
public static final String URL = "nacos.url";
public static final String TIMEOUT = "nacos.timout";
public static final String NAMESPACE = "nacos.namespace";
public static final long DEFAULT_TIMEOUT = 30000;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment