當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurableEnvironment.getPropertySources方法代碼示例

本文整理匯總了Java中org.springframework.core.env.ConfigurableEnvironment.getPropertySources方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableEnvironment.getPropertySources方法的具體用法?Java ConfigurableEnvironment.getPropertySources怎麽用?Java ConfigurableEnvironment.getPropertySources使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.env.ConfigurableEnvironment的用法示例。


在下文中一共展示了ConfigurableEnvironment.getPropertySources方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: postProcessEnvironment

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    // 此處可以http方式 到配置服務器拉取一堆公共配置+本項目個性配置的json串,拚到Properties裏
    // ......省略new Properties的過程
    MutablePropertySources propertySources = environment.getPropertySources();
    // addLast 結合下麵的 getOrder() 保證順序 讀者也可以試試其他姿勢的加載順序
    try {
        Properties props = getConfig(environment);
        for (Object key : props.keySet()) {
            String keyStr = key.toString();
            String value = props.getProperty(keyStr);
            if ("druid.writer.password,druid.reader.password".contains(keyStr)) {
                String dkey = props.getProperty("druid.key");
                dkey = DataUtil.isEmpty(dkey) ? Constants.DB_KEY : dkey;
                value = SecurityUtil.decryptDes(value, dkey.getBytes());
                props.setProperty(keyStr, value);
            }
            PropertiesUtil.getProperties().put(keyStr, value);
        }
        propertySources.addLast(new PropertiesPropertySource("thirdEnv", props));
    } catch (IOException e) {
        logger.error("", e);
    }
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:24,代碼來源:Configs.java

示例2: addDefaultProperty

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void addDefaultProperty(ConfigurableEnvironment environment, String name,
                                String value) {
    MutablePropertySources sources = environment.getPropertySources();
    Map<String, Object> map = null;
    if (sources.contains("defaultProperties")) {
        PropertySource<?> source = sources.get("defaultProperties");
        if (source instanceof MapPropertySource) {
            map = ((MapPropertySource) source).getSource();
        }
    } else {
        map = new LinkedHashMap<>();
        sources.addLast(new MapPropertySource("defaultProperties", map));
    }
    if (map != null) {
        map.put(name, value);
    }
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:18,代碼來源:MetricsEnvironmentPostProcessor.java

示例3: findProps

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
public static Properties findProps(ConfigurableEnvironment env, String prefix){
    Properties props = new Properties();

    for (PropertySource<?> source : env.getPropertySources()) {
        if (source instanceof EnumerablePropertySource) {
            EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
            for (String name : enumerable.getPropertyNames()) {
                if (name.startsWith(prefix)) {
                    props.putIfAbsent(name, enumerable.getProperty(name));
                }
            }

        }
    }

    return props;
}
 
開發者ID:taboola,項目名稱:taboola-cronyx,代碼行數:18,代碼來源:EnvironmentUtil.java

示例4: initialize

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    final ConfigurableEnvironment configurableEnvironment = applicationContext.getEnvironment();
    configurableEnvironment.setDefaultProfiles(Constants.STANDARD_DATABASE);

    final MutablePropertySources propertySources = configurableEnvironment.getPropertySources();

    AwsCloudRuntimeConfig.createPropertySource().ifPresent(awsPropertySource -> {
        propertySources.addLast(awsPropertySource);

        LOG.info("Using Amazon RDS profile");

        configurableEnvironment.setActiveProfiles(Constants.AMAZON_DATABASE);
    });

    LiquibaseConfig.replaceLiquibaseServiceLocator();
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:18,代碼來源:WebAppContextInitializer.java

示例5: postProcessBeanFactory

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
		throws BeansException {

	ConfigurableEnvironment env = beanFactory.getBean(ConfigurableEnvironment.class);
	MutablePropertySources propertySources = env.getPropertySources();

	registerPropertySources(
			beanFactory.getBeansOfType(
					org.springframework.vault.core.env.VaultPropertySource.class)
					.values(), propertySources);

	registerPropertySources(
			beanFactory
					.getBeansOfType(
							org.springframework.vault.core.env.LeaseAwareVaultPropertySource.class)
					.values(), propertySources);
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:19,代碼來源:VaultPropertySourceRegistrar.java

示例6: configurePropertySources

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
/**
 * Add, remove or re-order any {@link PropertySource}s in this application's
 * environment.
 * @param environment this application's environment
 * @param args arguments passed to the {@code run} method
 * @see #configureEnvironment(ConfigurableEnvironment, String[])
 */
protected void configurePropertySources(ConfigurableEnvironment environment,
		String[] args) {
	MutablePropertySources sources = environment.getPropertySources();
	if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
		sources.addLast(
				new MapPropertySource("defaultProperties", this.defaultProperties));
	}
	if (this.addCommandLineProperties && args.length > 0) {
		String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
		if (sources.contains(name)) {
			PropertySource<?> source = sources.get(name);
			CompositePropertySource composite = new CompositePropertySource(name);
			composite.addPropertySource(new SimpleCommandLinePropertySource(
					name + "-" + args.hashCode(), args));
			composite.addPropertySource(source);
			sources.replace(name, composite);
		}
		else {
			sources.addFirst(new SimpleCommandLinePropertySource(args));
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:30,代碼來源:SpringApplication.java

示例7: postProcessEnvironment

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
		Properties properties = new Properties();
		addWithPrefix(properties, getPropertiesFromApplication(environment),
				"vcap.application.");
		addWithPrefix(properties, getPropertiesFromServices(environment),
				"vcap.services.");
		MutablePropertySources propertySources = environment.getPropertySources();
		if (propertySources.contains(
				CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
			propertySources.addAfter(
					CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
					new PropertiesPropertySource("vcap", properties));
		}
		else {
			propertySources
					.addFirst(new PropertiesPropertySource("vcap", properties));
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:23,代碼來源:CloudFoundryVcapEnvironmentPostProcessor.java

示例8: matchingPropertySource

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private Condition<ConfigurableEnvironment> matchingPropertySource(
		final Class<?> propertySourceClass, final String name) {
	return new Condition<ConfigurableEnvironment>("has property source") {

		@Override
		public boolean matches(ConfigurableEnvironment value) {
			for (PropertySource<?> source : value.getPropertySources()) {
				if (propertySourceClass.isInstance(source)
						&& (name == null || name.equals(source.getName()))) {
					return true;
				}
			}
			return false;
		}

	};
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:SpringApplicationTests.java

示例9: findZuulPropertySource

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private MapPropertySource findZuulPropertySource(ConfigurableEnvironment environment) {
  for (PropertySource<?> propertySource : environment.getPropertySources()) {
    if (propertySource instanceof MapPropertySource) {
      for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) {
        if (key.toLowerCase().startsWith(ZUUL_SERVICE_VERSIONS_ROOT)) {
          return (MapPropertySource) propertySource;
        }
      }
    }
  }
  return null;
}
 
開發者ID:gorelikov,項目名稱:spring-cloud-discovery-version-filter,代碼行數:13,代碼來源:PropertyTranslatorPostProcessor.java

示例10: propertySourceOrder

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Test
public void propertySourceOrder() throws Exception {
	SimpleNamingContextBuilder.emptyActivatedContextBuilder();

	ConfigurableEnvironment env = new StandardServletEnvironment();
	MutablePropertySources sources = env.getPropertySources();

	assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
	assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
	assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
	assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
	assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
	assertThat(sources.size(), is(5));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:StandardServletEnvironmentTests.java

示例11: addInlinedPropertiesToEnvironmentWithEmptyProperty

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
/**
 * @since 4.1.5
 */
@Test
@SuppressWarnings("rawtypes")
public void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
	ConfigurableEnvironment environment = new MockEnvironment();
	MutablePropertySources propertySources = environment.getPropertySources();
	propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
	assertEquals(0, propertySources.size());
	addInlinedPropertiesToEnvironment(environment, new String[] { "  " });
	assertEquals(1, propertySources.size());
	assertEquals(0, ((Map) propertySources.iterator().next().getSource()).size());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:TestPropertySourceUtilsTests.java

示例12: addJsonPropertySource

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void addJsonPropertySource(ConfigurableEnvironment environment,
		PropertySource<?> source) {
	MutablePropertySources sources = environment.getPropertySources();
	String name = findPropertySource(sources);
	if (sources.contains(name)) {
		sources.addBefore(name, source);
	}
	else {
		sources.addFirst(source);
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:SpringApplicationJsonEnvironmentPostProcessor.java

示例13: flattenPropertySources

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void flattenPropertySources(PropertySource<?> propertySource,
		MutablePropertySources result) {
	Object source = propertySource.getSource();
	if (source instanceof ConfigurableEnvironment) {
		ConfigurableEnvironment environment = (ConfigurableEnvironment) source;
		for (PropertySource<?> childSource : environment.getPropertySources()) {
			flattenPropertySources(childSource, result);
		}
	}
	else {
		result.addLast(propertySource);
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:14,代碼來源:ConfigurationPropertiesBindingPostProcessor.java

示例14: convertToStandardEnvironment

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private ConfigurableEnvironment convertToStandardEnvironment(
		ConfigurableEnvironment environment) {
	StandardEnvironment result = new StandardEnvironment();
	removeAllPropertySources(result.getPropertySources());
	result.setActiveProfiles(environment.getActiveProfiles());
	for (PropertySource<?> propertySource : environment.getPropertySources()) {
		if (!SERVLET_ENVIRONMENT_SOURCE_NAMES.contains(propertySource.getName())) {
			result.getPropertySources().addLast(propertySource);
		}
	}
	return result;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:SpringApplication.java

示例15: addEnvironment

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
/**
 * Add additional (high priority) values to an {@link Environment}. Name-value pairs
 * can be specified with colon (":") or equals ("=") separators.
 * @param environment the environment to modify
 * @param name the property source name
 * @param pairs the name:value pairs
 */
public static void addEnvironment(String name, ConfigurableEnvironment environment,
		String... pairs) {
	MutablePropertySources sources = environment.getPropertySources();
	Map<String, Object> map = getOrAdd(sources, name);
	for (String pair : pairs) {
		int index = getSeparatorIndex(pair);
		String key = pair.substring(0, index > 0 ? index : pair.length());
		String value = index > 0 ? pair.substring(index + 1) : "";
		map.put(key.trim(), value.trim());
	}
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:19,代碼來源:EnvironmentTestUtils.java


注:本文中的org.springframework.core.env.ConfigurableEnvironment.getPropertySources方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。