use of org.springframework.boot.env.OriginTrackedMapPropertySource in project helio-starters by uncarbon97.
the class AdaptHistoryVersionAutoConfiguration method setEnvironment.
@Override
public void setEnvironment(@NonNull Environment env) {
try {
ConfigurableEnvironment c = (ConfigurableEnvironment) env;
MutablePropertySources sources = c.getPropertySources();
Map<String, Object> newMap = new LinkedHashMap<>();
for (PropertySource<?> source : sources) {
if (source instanceof OriginTrackedMapPropertySource) {
// 根据类判断是否为 SpringBoot .yml 或者 .properties 的配置
Map<String, Object> bootProp = ((OriginTrackedMapPropertySource) source).getSource();
for (String key : bootProp.keySet()) {
if (key != null) {
for (int i = 0; i < oldPropertyPrefixes.length; i++) {
if (key.startsWith(oldPropertyPrefixes[i])) {
/*
将配置文件中所有 [helio.crud.tenant.] 开头的配置转移到 [helio.tenant.] 下
实践测试 只对 @Value 注解有效
*/
String newKey = StrUtil.replace(key, oldPropertyPrefixes[i], newPropertyPrefixes[i]);
newMap.put(newKey, bootProp.get(key));
// 前缀相同的话,提示信息就保持一条(利用 Set 特性)
deprecatedPropertyWarnings.add(StrUtil.format("配置文件属性前缀 {}* 已过时、不向下兼容,请转移到 {}* 下", oldPropertyPrefixes[i], newPropertyPrefixes[i]));
}
}
}
}
}
}
// 追加到总配置里面
if (newMap.size() > 0) {
OriginTrackedMapPropertySource source = new OriginTrackedMapPropertySource("AdaptHistoryVersionAutoConfiguration", newMap);
// 追加到末尾,优先级最低
c.getPropertySources().addLast(source);
System.err.println("\n" + StrUtil.join("\n", deprecatedPropertyWarnings) + "\n");
}
} catch (Exception e) {
// ignored
}
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project spring-boot by spring-projects.
the class IntegrationPropertiesEnvironmentPostProcessor method registerIntegrationPropertiesPropertySource.
protected void registerIntegrationPropertiesPropertySource(ConfigurableEnvironment environment, Resource resource) {
PropertiesPropertySourceLoader loader = new PropertiesPropertySourceLoader();
try {
OriginTrackedMapPropertySource propertyFileSource = (OriginTrackedMapPropertySource) loader.load("META-INF/spring.integration.properties", resource).get(0);
environment.getPropertySources().addLast(new IntegrationPropertiesPropertySource(propertyFileSource));
} catch (IOException ex) {
throw new IllegalStateException("Failed to load integration properties from " + resource, ex);
}
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project spring-boot by spring-projects.
the class PropertiesMigrationReporter method mapPropertiesWithReplacement.
private PropertySource<?> mapPropertiesWithReplacement(PropertiesMigrationReport report, String name, List<PropertyMigration> properties) {
report.add(name, properties);
List<PropertyMigration> renamed = properties.stream().filter(PropertyMigration::isCompatibleType).collect(Collectors.toList());
if (renamed.isEmpty()) {
return null;
}
String target = "migrate-" + name;
Map<String, OriginTrackedValue> content = new LinkedHashMap<>();
for (PropertyMigration candidate : renamed) {
OriginTrackedValue value = OriginTrackedValue.of(candidate.getProperty().getValue(), candidate.getProperty().getOrigin());
content.put(candidate.getMetadata().getDeprecation().getReplacement(), value);
}
return new OriginTrackedMapPropertySource(target, content);
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project innovation-funding-service by InnovateUKGitHub.
the class StubDevPropertiesPostProcessor method registerPropertySource.
protected void registerPropertySource(ConfigurableEnvironment environment, Resource resource) {
PropertySourceLoader loader = new YamlPropertySourceLoader();
try {
OriginTrackedMapPropertySource propertyFileSource = (OriginTrackedMapPropertySource) loader.load(AUTOCONFIG_STUBDEV_YML, resource).get(0);
environment.getPropertySources().addFirst(propertyFileSource);
} catch (IOException ex) {
throw new IllegalStateException("Failed to load properties from " + resource, ex);
}
}
use of org.springframework.boot.env.OriginTrackedMapPropertySource in project innovation-funding-service by InnovateUKGitHub.
the class YamlPropertyLoader method registerPropertySource.
/**
* Loads yaml properties into the spring context as a property source.
* @param environment the spring ConfigurableEnvironment
* @param resource the yaml file
*/
public static void registerPropertySource(ConfigurableEnvironment environment, Resource resource) {
PropertySourceLoader loader = new YamlPropertySourceLoader();
try {
OriginTrackedMapPropertySource propertyFileSource = (OriginTrackedMapPropertySource) loader.load(YamlPropertyLoader.class.getSimpleName() + "->" + resource.getFilename(), resource).get(0);
environment.getPropertySources().addFirst(propertyFileSource);
} catch (IOException ex) {
throw new IllegalStateException("Failed to load properties from " + resource, ex);
}
}
Aggregations