Merge pull request #136 from pbting/1.x
nacos config support custom config dataid and grouppull/153/head
commit
e812515250
@ -1,20 +1,37 @@
|
||||
{"properties": [
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.encode",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "UTF-8",
|
||||
"description": "default encode for nacos config content."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.prefix",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "${spring.application.name}",
|
||||
"description": "the prefix of dataId, nacos config data meta info. dataId = prefix + '-' + ${spring.active.profile} + `.` + ${spring.cloud.nacos.config.file-extension}."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.file-extension",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "properties",
|
||||
"description": "the suffix of nacos config dataId, also the file extension of config content, only support properties now."
|
||||
}
|
||||
]}
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.encode",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "UTF-8",
|
||||
"description": "default encode for nacos config content."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.prefix",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "${spring.application.name}",
|
||||
"description": "the prefix of dataId, nacos config data meta info. dataId = prefix + '-' + ${spring.active.profile} + `.` + ${spring.cloud.nacos.config.file-extension}."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.file-extension",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "properties",
|
||||
"description": "the suffix of nacos config dataId, also the file extension of config content, only support properties now."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.shared-dataids",
|
||||
"type": "java.lang.String",
|
||||
"description": "the dataids for configurable multiple shared configurations , multiple separated by commas ."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.refreshable-dataids",
|
||||
"type": "java.lang.String",
|
||||
"description": "refreshable dataids , multiple separated by commas ."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.config.ext-config",
|
||||
"type": "java.util.List",
|
||||
"description": "a set of extended configurations ."
|
||||
}
|
||||
]
|
||||
}
|
@ -1,8 +1,16 @@
|
||||
{"properties": [
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.service",
|
||||
"type": "java.lang.String",
|
||||
"defaultValue": "${spring.application.name}",
|
||||
"description": "the service name to register, default value is ${spring.application.name}."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.namingLoadCacheAtStart",
|
||||
"type": "java.lang.Boolean",
|
||||
"defaultValue": "false",
|
||||
"description": "naming load from local cache at application start ."
|
||||
}
|
||||
]}
|
||||
]
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package org.springframework.cloud.alicloud.context.nacos;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
/**
|
||||
* A listener that prepare initialize the nacos configuration for aliyun acm
|
||||
*
|
||||
* @author pbting
|
||||
*/
|
||||
public class NacosParameterInitListener
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(NacosParameterInitListener.class);
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
preparedNacosConfiguration();
|
||||
}
|
||||
|
||||
private void preparedNacosConfiguration() {
|
||||
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
|
||||
.buildEdasChangeOrderConfiguration();
|
||||
log.info("Initialize Nacos Parameter from edas change order,is edas managed {}.",
|
||||
edasChangeOrderConfiguration.isEdasManaged());
|
||||
if (!edasChangeOrderConfiguration.isEdasManaged()) {
|
||||
return;
|
||||
}
|
||||
// initialize nacos configuration
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.server-addr", "");
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.endpoint",
|
||||
edasChangeOrderConfiguration.getAddressServerDomain());
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.namespace",
|
||||
edasChangeOrderConfiguration.getTenantId());
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.access-key",
|
||||
edasChangeOrderConfiguration.getDauthAccessKey());
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.secret-key",
|
||||
edasChangeOrderConfiguration.getDauthSecretKey());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue