org.springframework.core.env.PropertySource#containsProperty ( )源码实例Demo

下面列出了org.springframework.core.env.PropertySource#containsProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    PropertySource<?> system = environment.getPropertySources().get(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
    Map<String, Object> prefixed = new LinkedHashMap<>();
    for (String property: PROPERTIES) {
        if (system.containsProperty(property)) {
            if (property.startsWith(LOG_PREFIX)) {
                prefixed.put("logging.level.org.teiid." + property.substring(LOG_PREFIX.length()),
                        system.getProperty(property));
            } else if (property.equals("LOGGING_LEVEL_ORG_TEIID")) {
                prefixed.put("logging.level.org.teiid", system.getProperty(property));
            }
        }
    }
    environment.getPropertySources().addAfter(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
            new MapPropertySource("prefixer", prefixed));
}
 
private void mergeDefaultProperties(MutablePropertySources environment,
		MutablePropertySources bootstrap) {
	String name = DEFAULT_PROPERTIES;
	if (bootstrap.contains(name)) {
		PropertySource<?> source = bootstrap.get(name);
		if (!environment.contains(name)) {
			environment.addLast(source);
		}
		else {
			PropertySource<?> target = environment.get(name);
			if (target instanceof MapPropertySource && target != source
					&& source instanceof MapPropertySource) {
				Map<String, Object> targetMap = ((MapPropertySource) target)
						.getSource();
				Map<String, Object> map = ((MapPropertySource) source).getSource();
				for (String key : map.keySet()) {
					if (!target.containsProperty(key)) {
						targetMap.put(key, map.get(key));
					}
				}
			}
		}
	}
	mergeAdditionalPropertySources(environment, bootstrap);
}
 
private boolean hasOurPriceProperties(PropertySource<?> system) {
    if (system.containsProperty(CALCUATION_MODE) && system.containsProperty(GROSS_CALCULATION_TAX_RATE)) {
        return true;
    } else
        return false;
}