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[] activeProfiles;
|
||||
|
||||
/**
|
||||
* the dataids for configurable multiple shared configurations , multiple separated by
|
||||
* commas .
|
||||
@ -145,11 +143,6 @@ public class NacosConfigProperties {
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.activeProfiles = environment.getActiveProfiles();
|
||||
}
|
||||
|
||||
// todo sts support
|
||||
|
||||
public boolean isEnabled() {
|
||||
@ -260,10 +253,6 @@ public class NacosConfigProperties {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String[] getActiveProfiles() {
|
||||
return activeProfiles;
|
||||
}
|
||||
|
||||
public String getSharedDataids() {
|
||||
return sharedDataids;
|
||||
}
|
||||
@ -292,10 +281,6 @@ public class NacosConfigProperties {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setActiveProfiles(String[] activeProfiles) {
|
||||
this.activeProfiles = activeProfiles;
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
/**
|
||||
* the data id of extended configuration
|
||||
@ -344,8 +329,7 @@ public class NacosConfigProperties {
|
||||
+ endpoint + '\'' + ", namespace='" + namespace + '\'' + ", accessKey='"
|
||||
+ accessKey + '\'' + ", secretKey='" + secretKey + '\''
|
||||
+ ", contextPath='" + contextPath + '\'' + ", clusterName='" + clusterName
|
||||
+ '\'' + ", name='" + name + '\'' + ", activeProfiles="
|
||||
+ Arrays.toString(activeProfiles) + ", sharedDataids='" + sharedDataids
|
||||
+ '\'' + ", name='" + name + '\'' + ", sharedDataids='" + sharedDataids
|
||||
+ '\'' + ", refreshableDataids='" + refreshableDataids + '\''
|
||||
+ ", extConfig=" + extConfig + '}';
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
timeout);
|
||||
String name = nacosConfigProperties.getName();
|
||||
|
||||
String nacosGroup = nacosConfigProperties.getGroup();
|
||||
String dataIdPrefix = nacosConfigProperties.getPrefix();
|
||||
if (StringUtils.isEmpty(dataIdPrefix)) {
|
||||
dataIdPrefix = name;
|
||||
@ -81,17 +80,12 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
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(
|
||||
NACOS_PROPERTY_SOURCE_NAME);
|
||||
|
||||
loadSharedConfiguration(composite);
|
||||
loadExtConfiguration(composite);
|
||||
loadApplicationConfiguration(composite, nacosGroup, dataIdPrefix, fileExtension);
|
||||
loadApplicationConfiguration(composite, dataIdPrefix, nacosConfigProperties, env);
|
||||
|
||||
return composite;
|
||||
}
|
||||
@ -152,11 +146,15 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
}
|
||||
|
||||
private void loadApplicationConfiguration(
|
||||
CompositePropertySource compositePropertySource, String nacosGroup,
|
||||
String dataIdPrefix, String fileExtension) {
|
||||
CompositePropertySource compositePropertySource, String dataIdPrefix,
|
||||
NacosConfigProperties properties, Environment environment) {
|
||||
|
||||
String fileExtension = properties.getFileExtension();
|
||||
String nacosGroup = properties.getGroup();
|
||||
|
||||
loadNacosDataIfPresent(compositePropertySource,
|
||||
dataIdPrefix + DOT + fileExtension, nacosGroup, fileExtension, true);
|
||||
for (String profile : nacosConfigProperties.getActiveProfiles()) {
|
||||
for (String profile : environment.getActiveProfiles()) {
|
||||
String dataId = dataIdPrefix + SEP1 + profile + DOT + fileExtension;
|
||||
loadNacosDataIfPresent(compositePropertySource, dataId, nacosGroup,
|
||||
fileExtension, true);
|
||||
|
@ -163,7 +163,6 @@ public class NacosConfigurationTests {
|
||||
checkoutNacosConfigFileExtension();
|
||||
checkoutNacosConfigTimeout();
|
||||
checkoutNacosConfigEncode();
|
||||
checkoutNacosConfigProfiles();
|
||||
|
||||
checkoutEndpoint();
|
||||
checkoutDataLoad();
|
||||
@ -239,11 +238,6 @@ public class NacosConfigurationTests {
|
||||
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 {
|
||||
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
||||
refreshHistory);
|
||||
|
Loading…
x
Reference in New Issue
Block a user