当前位置: 首页>>代码示例>>Java>>正文


Java MutablePropertySources类代码示例

本文整理汇总了Java中org.springframework.core.env.MutablePropertySources的典型用法代码示例。如果您正苦于以下问题:Java MutablePropertySources类的具体用法?Java MutablePropertySources怎么用?Java MutablePropertySources使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MutablePropertySources类属于org.springframework.core.env包,在下文中一共展示了MutablePropertySources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addKeyVaultPropertySource

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
public void addKeyVaultPropertySource() {
    final String clientId = getProperty(environment, Constants.AZURE_CLIENTID);
    final String clientKey = getProperty(environment, Constants.AZURE_CLIENTKEY);
    final String vaultUri = getProperty(environment, Constants.AZURE_KEYVAULT_VAULT_URI);

    final long timeAcquiringTimeoutInSeconds = environment.getProperty(
            Constants.AZURE_TOKEN_ACQUIRE_TIMEOUT_IN_SECONDS, Long.class, 60L);

    final KeyVaultClient kvClient = new KeyVaultClient(
            new AzureKeyVaultCredential(clientId, clientKey, timeAcquiringTimeoutInSeconds));

    try {
        final MutablePropertySources sources = environment.getPropertySources();
        final KeyVaultOperation kvOperation = new KeyVaultOperation(kvClient, vaultUri);

        if (sources.contains(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
            sources.addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
                    new KeyVaultPropertySource(kvOperation));
        } else {
            sources.addFirst(new KeyVaultPropertySource(kvOperation));
        }

    } catch (Exception ex) {
        throw new IllegalStateException("Failed to configure KeyVault property source", ex);
    }
}
 
开发者ID:Microsoft,项目名称:azure-spring-boot,代码行数:27,代码来源:KeyVaultEnvironmentPostProcessorHelper.java

示例2: postProcessEnvironment

import org.springframework.core.env.MutablePropertySources; //导入依赖的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

示例3: addDefaultProperty

import org.springframework.core.env.MutablePropertySources; //导入依赖的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

示例4: getPropertyNames

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
@Override
public Stream<String> getPropertyNames() throws UnsupportedOperationException {
	List<String> names = new LinkedList<>();
	if (ConfigurableEnvironment.class.isAssignableFrom(getEnvironment().getClass())) {
		MutablePropertySources propertySources = ((ConfigurableEnvironment) getEnvironment()).getPropertySources();
		if (propertySources != null) {
			Iterator<PropertySource<?>> i = propertySources.iterator();
			while (i.hasNext()) {
				PropertySource<?> source = i.next();
				if (source instanceof EnumerablePropertySource) {
					String[] propertyNames = ((EnumerablePropertySource<?>) source).getPropertyNames();
					if (propertyNames != null) {
						names.addAll(Arrays.asList(propertyNames));
					}
				}
			}
		}
	}
	return names.stream();
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:21,代码来源:DefaultEnvironmentConfigPropertyProvider.java

示例5: initialize

import org.springframework.core.env.MutablePropertySources; //导入依赖的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

示例6: withExplicitName

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
@Test
public void withExplicitName() {
	AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
	ctx.register(ConfigWithExplicitName.class);
	ctx.refresh();
	assertTrue("property source p1 was not added",
			ctx.getEnvironment().getPropertySources().contains("p1"));
	assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));

	// assert that the property source was added last to the set of sources
	String name;
	MutablePropertySources sources = ctx.getEnvironment().getPropertySources();
	Iterator<org.springframework.core.env.PropertySource<?>> iterator = sources.iterator();
	do {
		name = iterator.next().getName();
	}
	while(iterator.hasNext());

	assertThat(name, is("p1"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:PropertySourceAnnotationTests.java

示例7: customizePropertySources

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
    super.customizePropertySources(propertySources);
    propertySources.addFirst(new PropertySource<Object>("TestAppServerProperty"){

        @Override
        public Object getProperty(String name) {

            if(name.equals("server.port")){
                return String.valueOf(port);
            }
            return null;
        }

    });
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:17,代码来源:SpringApplicationStarter.java

示例8: customizePropertySources

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
	super.customizePropertySources(propertySources);
	propertySources.addFirst(new PropertySource<Object>("TestAppServerProperty"){

		@Override
		public Object getProperty(String name) {
			
			if(name.equals("server.port")){
				return String.valueOf(serverPort);
			}
			return null;
		}
		
	});
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:17,代码来源:TestMetaServer.java

示例9: explicitPropertySourcesExcludesLocalProperties

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void explicitPropertySourcesExcludesLocalProperties() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerBeanDefinition("testBean",
			genericBeanDefinition(TestBean.class)
				.addPropertyValue("name", "${my.name}")
				.getBeanDefinition());

	MutablePropertySources propertySources = new MutablePropertySources();
	propertySources.addLast(new MockPropertySource());

	PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
	pc.setPropertySources(propertySources);
	pc.setProperties(new Properties() {{
		put("my.name", "local");
	}});
	pc.setIgnoreUnresolvablePlaceholders(true);
	pc.postProcessBeanFactory(bf);
	assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:PropertySourcesPlaceholderConfigurerTests.java

示例10: postProcess

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
public void postProcess(ConfigurableListableBeanFactory beanFactory) {
    // 注册 Spring 属性配置
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    MutablePropertySources mutablePropertySources = new MutablePropertySources();
    mutablePropertySources.addLast(new PropertySource<String>(Configs.class.getName()) {
        @Override
        public String getProperty(String name) {
            return Configs.getString(name);
        }
    });
    configurer.setPropertySources(mutablePropertySources);
    configurer.postProcessBeanFactory(beanFactory);

    /*
     * 注册 @ConfigValue 处理器. ConfigValueBeanPostProcessor 实现了 ApplicationListener 接口, 不能使用
     * beanFactory.addBeanPostProcessor() 来注册实例.
     */
    beanFactory.registerSingleton(ConfigValueBeanPostProcessor.class.getName(),
            new ConfigValueBeanPostProcessor(beanFactory));
}
 
开发者ID:kevin70,项目名称:setaria,代码行数:21,代码来源:ConfigValueBeanFactoryPostProcessor.java

示例11: loadPropertySources

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
private PropertySources loadPropertySources(String[] locations,
		boolean mergeDefaultSources) {
	try {
		PropertySourcesLoader loader = new PropertySourcesLoader();
		for (String location : locations) {
			Resource resource = this.resourceLoader
					.getResource(this.environment.resolvePlaceholders(location));
			String[] profiles = this.environment.getActiveProfiles();
			for (int i = profiles.length; i-- > 0;) {
				String profile = profiles[i];
				loader.load(resource, profile);
			}
			loader.load(resource);
		}
		MutablePropertySources loaded = loader.getPropertySources();
		if (mergeDefaultSources) {
			for (PropertySource<?> propertySource : this.propertySources) {
				loaded.addLast(propertySource);
			}
		}
		return loaded;
	}
	catch (IOException ex) {
		throw new IllegalStateException(ex);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:ConfigurationPropertiesBindingPostProcessor.java

示例12: finishAndRelocate

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
public static void finishAndRelocate(MutablePropertySources propertySources) {
	String name = APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME;
	ConfigurationPropertySources removed = (ConfigurationPropertySources) propertySources
			.get(name);
	if (removed != null) {
		for (PropertySource<?> propertySource : removed.sources) {
			if (propertySource instanceof EnumerableCompositePropertySource) {
				EnumerableCompositePropertySource composite = (EnumerableCompositePropertySource) propertySource;
				for (PropertySource<?> nested : composite.getSource()) {
					propertySources.addAfter(name, nested);
					name = nested.getName();
				}
			}
			else {
				propertySources.addAfter(name, propertySource);
			}
		}
		propertySources.remove(APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:ConfigFileApplicationListener.java

示例13: configurePropertySources

import org.springframework.core.env.MutablePropertySources; //导入依赖的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

示例14: postProcessEnvironment

import org.springframework.core.env.MutablePropertySources; //导入依赖的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

示例15: testBindWithDashPrefix

import org.springframework.core.env.MutablePropertySources; //导入依赖的package包/类
@Test
public void testBindWithDashPrefix() throws Exception {
	// gh-4045
	this.targetName = "foo-bar";
	MutablePropertySources propertySources = new MutablePropertySources();
	propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment",
			Collections.<String, Object>singletonMap("FOO_BAR_NAME", "blah")));
	propertySources.addLast(new RandomValuePropertySource());
	setupFactory();
	this.factory.setPropertySources(propertySources);
	this.factory.afterPropertiesSet();
	Foo foo = this.factory.getObject();
	assertThat(foo.name).isEqualTo("blah");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:PropertiesConfigurationFactoryTests.java


注:本文中的org.springframework.core.env.MutablePropertySources类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。