Skip to content

Commit

Permalink
✨ 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunMengLu committed Sep 26, 2024
1 parent 8c72a12 commit 443ee71
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
* 自定义资源文件读取,优先级最低
Expand Down Expand Up @@ -92,13 +91,13 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
List<PropertyFile> sortedPropertyList = propertyFileList.stream()
.distinct()
.sorted()
.collect(Collectors.toList());
.toList();
ConfigurableEnvironment environment = beanFactory.getBean(ConfigurableEnvironment.class);
MutablePropertySources propertySources = environment.getPropertySources();

// 只支持 activeProfiles,没有必要支持 spring.profiles.include。
String[] activeProfiles = environment.getActiveProfiles();
ArrayList<PropertySource> propertySourceList = new ArrayList<>();
List<PropertySource> propertySourceList = new ArrayList<>();
for (String profile : activeProfiles) {
for (PropertyFile propertyFile : sortedPropertyList) {
// 不加载 ActiveProfile 的配置文件
Expand All @@ -112,7 +111,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
}
String location = propertyFile.getLocation();
String filePath = StringUtils.stripFilenameExtension(location);
String profiledLocation = filePath + "-" + profile + "." + extension;
String profiledLocation = filePath + '-' + profile + '.' + extension;
Resource resource = resourceLoader.getResource(profiledLocation);
loadPropertySource(profiledLocation, resource, loader, propertySourceList);
}
Expand All @@ -135,7 +134,7 @@ private static void loadPropertySource(String location, Resource resource,
PropertySourceLoader loader,
List<PropertySource> sourceList) {
if (resource.exists()) {
String name = "bladePropertySource: [" + location + "]";
String name = "bladePropertySource: [" + location + ']';
try {
sourceList.addAll(loader.load(name, resource));
} catch (IOException e) {
Expand Down

0 comments on commit 443ee71

Please sign in to comment.