我有几个JSON文件作为属性,并定义了一个JSON加载器来加载它们
启动应用程序时,将属性添加为配置文件。
-Dspring.profiles.active=FileNameA,FileNameB, FileNameC, FileNameD
JSON文件加载器
public class JsonPropertySourceLoader implements PropertySourceLoader {
@Override
public String[] getFileExtensions() {
return new String[]{"json"};
}
@Override
public PropertySource<?> load(String name, Resource resource, String profile) throws IOException {
Map<String, Object> result = mapPropertySource(resource);
return new MapPropertySource(name, result);
}
private Map<String, Object> mapPropertySource(Resource resource) throws IOException {
if (resource == null) {
return null;
}
String srcString = StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset());
return JsonParserFactory.getJsonParser().parseMap(srcString);
}
}
问题,当我检查日志时,看到以下日志。并且重复为每个配置文件加载它。有什么建议吗?
加载{applicationConfig:[classpath:/ FileNameA]} {FileNameA}配置文件:{null}
加载{applicationConfig:[classpath:/ FileNameA] #FileNameA} {FileNameA}配置文件:{FileNameA}
正在加载{applicationConfig:[classpath:/ FileNameA] #FileNameB} {FileNameA}配置文件:{FileNameB}
正在加载{applicationConfig:[classpath:/ FileNameA] #FileNameC} {FileNameA}配置文件:{FileNameC}
正在加载{applicationConfig:[classpath:/ FileNameA] #FileNameD} {FileNameA}配置文件:{FileNameD}