下面列出了org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder#withJsonResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Resolve all configuration metadata properties prefixed with {@code spring.cloud.deployer.}
*
* @return the list
*/
public List<ConfigurationMetadataProperty> resolve() {
List<ConfigurationMetadataProperty> metadataProperties = new ArrayList<>();
ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
try {
Resource[] resources = applicationContext.getResources(CONFIGURATION_METADATA_PATTERN);
for (Resource resource : resources) {
builder.withJsonResource(resource.getInputStream());
}
}
catch (IOException e) {
throw new SkipperException("Unable to read configuration metadata", e);
}
ConfigurationMetadataRepository metadataRepository = builder.build();
Map<String, ConfigurationMetadataGroup> groups = metadataRepository.getAllGroups();
// 1. go through all groups and their properties
// 2. filter 'spring.cloud.deployer.' properties
// 3. pass in only group includes, empty passes through all
// 4. pass in group excludes
// 5. same logic for properties for includes and excludes
// 6. what's left is white/black listed props
groups.values().stream()
.filter(g -> g.getId().startsWith(KEY_PREFIX))
.filter(groupEmptyOrAnyMatch(deployerProperties.getGroupIncludes()))
.filter(groupNoneMatch(deployerProperties.getGroupExcludes()))
.forEach(g -> {
g.getProperties().values().stream()
.filter(propertyEmptyOrAnyMatch(deployerProperties.getPropertyIncludes()))
.filter(propertyNoneMatch(deployerProperties.getPropertyExcludes()))
.forEach(p -> {
metadataProperties.add(p);
});
});
return metadataProperties;
}
/**
* Resolve all configuration metadata properties prefixed with {@code spring.cloud.deployer.}
*
* @return the list
*/
public List<ConfigurationMetadataProperty> resolve() {
List<ConfigurationMetadataProperty> metadataProperties = new ArrayList<>();
ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
try {
Resource[] resources = applicationContext.getResources(CONFIGURATION_METADATA_PATTERN);
for (Resource resource : resources) {
builder.withJsonResource(resource.getInputStream());
}
}
catch (IOException e) {
throw new SkipperException("Unable to read configuration metadata", e);
}
ConfigurationMetadataRepository metadataRepository = builder.build();
Map<String, ConfigurationMetadataGroup> groups = metadataRepository.getAllGroups();
// 1. go through all groups and their properties
// 2. filter 'spring.cloud.deployer.' properties
// 3. pass in only group includes, empty passes through all
// 4. pass in group excludes
// 5. same logic for properties for includes and excludes
// 6. what's left is white/black listed props
groups.values().stream()
.filter(g -> g.getId().startsWith(KEY_PREFIX))
.filter(groupEmptyOrAnyMatch(deployerProperties.getGroupIncludes()))
.filter(groupNoneMatch(deployerProperties.getGroupExcludes()))
.forEach(g -> {
g.getProperties().values().stream()
.filter(propertyEmptyOrAnyMatch(deployerProperties.getPropertyIncludes()))
.filter(propertyNoneMatch(deployerProperties.getPropertyExcludes()))
.forEach(p -> {
metadataProperties.add(p);
});
});
return metadataProperties;
}