mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Fixes #404
This commit is contained in:
parent
412c1851d3
commit
fa0b5a8664
@ -122,8 +122,6 @@ public class NacosConfigProperties {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String[] activeProfiles;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the dataids for configurable multiple shared configurations , multiple separated by
|
* the dataids for configurable multiple shared configurations , multiple separated by
|
||||||
* commas .
|
* commas .
|
||||||
@ -145,11 +143,6 @@ public class NacosConfigProperties {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.activeProfiles = environment.getActiveProfiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo sts support
|
// todo sts support
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@ -260,10 +253,6 @@ public class NacosConfigProperties {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getActiveProfiles() {
|
|
||||||
return activeProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSharedDataids() {
|
public String getSharedDataids() {
|
||||||
return sharedDataids;
|
return sharedDataids;
|
||||||
}
|
}
|
||||||
@ -292,10 +281,6 @@ public class NacosConfigProperties {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActiveProfiles(String[] activeProfiles) {
|
|
||||||
this.activeProfiles = activeProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Config {
|
public static class Config {
|
||||||
/**
|
/**
|
||||||
* the data id of extended configuration
|
* the data id of extended configuration
|
||||||
@ -344,8 +329,7 @@ public class NacosConfigProperties {
|
|||||||
+ endpoint + '\'' + ", namespace='" + namespace + '\'' + ", accessKey='"
|
+ endpoint + '\'' + ", namespace='" + namespace + '\'' + ", accessKey='"
|
||||||
+ accessKey + '\'' + ", secretKey='" + secretKey + '\''
|
+ accessKey + '\'' + ", secretKey='" + secretKey + '\''
|
||||||
+ ", contextPath='" + contextPath + '\'' + ", clusterName='" + clusterName
|
+ ", contextPath='" + contextPath + '\'' + ", clusterName='" + clusterName
|
||||||
+ '\'' + ", name='" + name + '\'' + ", activeProfiles="
|
+ '\'' + ", name='" + name + '\'' + ", sharedDataids='" + sharedDataids
|
||||||
+ Arrays.toString(activeProfiles) + ", sharedDataids='" + sharedDataids
|
|
||||||
+ '\'' + ", refreshableDataids='" + refreshableDataids + '\''
|
+ '\'' + ", refreshableDataids='" + refreshableDataids + '\''
|
||||||
+ ", extConfig=" + extConfig + '}';
|
+ ", extConfig=" + extConfig + '}';
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,6 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
timeout);
|
timeout);
|
||||||
String name = nacosConfigProperties.getName();
|
String name = nacosConfigProperties.getName();
|
||||||
|
|
||||||
String nacosGroup = nacosConfigProperties.getGroup();
|
|
||||||
String dataIdPrefix = nacosConfigProperties.getPrefix();
|
String dataIdPrefix = nacosConfigProperties.getPrefix();
|
||||||
if (StringUtils.isEmpty(dataIdPrefix)) {
|
if (StringUtils.isEmpty(dataIdPrefix)) {
|
||||||
dataIdPrefix = name;
|
dataIdPrefix = name;
|
||||||
@ -81,17 +80,12 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
dataIdPrefix = env.getProperty("spring.application.name");
|
dataIdPrefix = env.getProperty("spring.application.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> profiles = Arrays.asList(env.getActiveProfiles());
|
|
||||||
nacosConfigProperties.setActiveProfiles(profiles.toArray(new String[0]));
|
|
||||||
|
|
||||||
String fileExtension = nacosConfigProperties.getFileExtension();
|
|
||||||
|
|
||||||
CompositePropertySource composite = new CompositePropertySource(
|
CompositePropertySource composite = new CompositePropertySource(
|
||||||
NACOS_PROPERTY_SOURCE_NAME);
|
NACOS_PROPERTY_SOURCE_NAME);
|
||||||
|
|
||||||
loadSharedConfiguration(composite);
|
loadSharedConfiguration(composite);
|
||||||
loadExtConfiguration(composite);
|
loadExtConfiguration(composite);
|
||||||
loadApplicationConfiguration(composite, nacosGroup, dataIdPrefix, fileExtension);
|
loadApplicationConfiguration(composite, dataIdPrefix, nacosConfigProperties, env);
|
||||||
|
|
||||||
return composite;
|
return composite;
|
||||||
}
|
}
|
||||||
@ -152,11 +146,15 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadApplicationConfiguration(
|
private void loadApplicationConfiguration(
|
||||||
CompositePropertySource compositePropertySource, String nacosGroup,
|
CompositePropertySource compositePropertySource, String dataIdPrefix,
|
||||||
String dataIdPrefix, String fileExtension) {
|
NacosConfigProperties properties, Environment environment) {
|
||||||
|
|
||||||
|
String fileExtension = properties.getFileExtension();
|
||||||
|
String nacosGroup = properties.getGroup();
|
||||||
|
|
||||||
loadNacosDataIfPresent(compositePropertySource,
|
loadNacosDataIfPresent(compositePropertySource,
|
||||||
dataIdPrefix + DOT + fileExtension, nacosGroup, fileExtension, true);
|
dataIdPrefix + DOT + fileExtension, nacosGroup, fileExtension, true);
|
||||||
for (String profile : nacosConfigProperties.getActiveProfiles()) {
|
for (String profile : environment.getActiveProfiles()) {
|
||||||
String dataId = dataIdPrefix + SEP1 + profile + DOT + fileExtension;
|
String dataId = dataIdPrefix + SEP1 + profile + DOT + fileExtension;
|
||||||
loadNacosDataIfPresent(compositePropertySource, dataId, nacosGroup,
|
loadNacosDataIfPresent(compositePropertySource, dataId, nacosGroup,
|
||||||
fileExtension, true);
|
fileExtension, true);
|
||||||
|
@ -163,7 +163,6 @@ public class NacosConfigurationTests {
|
|||||||
checkoutNacosConfigFileExtension();
|
checkoutNacosConfigFileExtension();
|
||||||
checkoutNacosConfigTimeout();
|
checkoutNacosConfigTimeout();
|
||||||
checkoutNacosConfigEncode();
|
checkoutNacosConfigEncode();
|
||||||
checkoutNacosConfigProfiles();
|
|
||||||
|
|
||||||
checkoutEndpoint();
|
checkoutEndpoint();
|
||||||
checkoutDataLoad();
|
checkoutDataLoad();
|
||||||
@ -239,11 +238,6 @@ public class NacosConfigurationTests {
|
|||||||
Assert.assertEquals(environment.getProperty("user.age"), "12");
|
Assert.assertEquals(environment.getProperty("user.age"), "12");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkoutNacosConfigProfiles() {
|
|
||||||
assertEquals("NacosConfigProperties' profiles is wrong",
|
|
||||||
new String[] { "dev", "test" }, properties.getActiveProfiles());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkoutEndpoint() throws Exception {
|
private void checkoutEndpoint() throws Exception {
|
||||||
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
||||||
refreshHistory);
|
refreshHistory);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user