本文整理汇总了Java中org.springframework.context.support.PropertySourcesPlaceholderConfigurer类的典型用法代码示例。如果您正苦于以下问题:Java PropertySourcesPlaceholderConfigurer类的具体用法?Java PropertySourcesPlaceholderConfigurer怎么用?Java PropertySourcesPlaceholderConfigurer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertySourcesPlaceholderConfigurer类属于org.springframework.context.support包,在下文中一共展示了PropertySourcesPlaceholderConfigurer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: propertiesForIntegration
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
@Profile("integration")
public static PropertySourcesPlaceholderConfigurer propertiesForIntegration()
throws Exception {
String file = "application-integration-local.properties";
String envIntegration = System.getenv("CLOUDUNIT_JENKINS_CI");
if ("true".equalsIgnoreCase(envIntegration)) {
file = "application-integration.properties";
}
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
pspc.setLocations(getResources(file));
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setLocalOverride(true);
return pspc;
}
示例2: mergePropertySource
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
protected void mergePropertySource() throws Exception {
if (this.environment != null) {
this.addLast(new PropertySource<Environment>(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
} else {
logger.warn("The injected environment was null!");
}
if (this.locations != null && this.locations.length > 0) {
Properties localProperties = new Properties();
loadProperties(localProperties);
PropertySource<?> localPropertySource = new PropertiesPropertySource(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, localProperties);
if (this.localOverride) {
this.addFirst(localPropertySource);
} else {
this.addLast(localPropertySource);
}
}
}
示例3: registerBeanDefinitions
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
.getAnnotationAttributes(EnableApolloConfig.class.getName()));
String[] namespaces = attributes.getStringArray("value");
int order = attributes.getNumber("order");
PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
PropertySourcesPlaceholderConfigurer.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
PropertySourcesProcessor.class);
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
ApolloAnnotationProcessor.class);
}
示例4: propertyPlaceholderConfigurer
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
placeholderConfigurer.setFileEncoding("UTF-8");
Properties properties = EnvLoader.getEnvs();
if (properties.isEmpty()) {
ParamsHome.getInstance().init(StringUtils.EMPTY);
EnvLoader.init();
IniLoader.init();
properties = EnvLoader.getEnvs();
}
placeholderConfigurer.setProperties(properties);
return placeholderConfigurer;
}
示例5: postProcessEmbeddedServletContainerFactory
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Test
public void postProcessEmbeddedServletContainerFactory() throws Exception {
RootBeanDefinition bd = new RootBeanDefinition(
MockEmbeddedServletContainerFactory.class);
MutablePropertyValues pv = new MutablePropertyValues();
pv.add("port", "${port}");
bd.setPropertyValues(pv);
this.context.registerBeanDefinition("embeddedServletContainerFactory", bd);
PropertySourcesPlaceholderConfigurer propertySupport = new PropertySourcesPlaceholderConfigurer();
Properties properties = new Properties();
properties.put("port", 8080);
propertySupport.setProperties(properties);
this.context.registerBeanDefinition("propertySupport",
beanDefinition(propertySupport));
this.context.refresh();
assertThat(getEmbeddedServletContainerFactory().getContainer().getPort())
.isEqualTo(8080);
}
示例6: postProcess
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的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));
}
示例7: getPlaceholderConfigurerResources
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
public Optional<Resource[]> getPlaceholderConfigurerResources() {
List<Resource> resources = Lists.newArrayList();
Iterator<Entry<String, PropertySourcesPlaceholderConfigurer>> iterator = placeholderMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, PropertySourcesPlaceholderConfigurer> entry = iterator.next();
Optional<Resource[]> optional = this.<Resource[]> getPropertyValue(entry.getValue(),
PropertySourcesEnum.LOCATIONS.getName());
if (optional.isPresent()) {
resources.addAll(Arrays.asList(optional.get()));
}
}
return Optional.fromNullable(resources.toArray(new Resource[0]));
}
示例8: deducePropertySources
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
private PropertySources deducePropertySources() {
PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
if (configurer != null) {
// Flatten the sources into a single list so they can be iterated
return new FlatPropertySources(configurer.getAppliedPropertySources());
}
if (this.environment instanceof ConfigurableEnvironment) {
MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment)
.getPropertySources();
return new FlatPropertySources(propertySources);
}
// empty, so not very useful, but fulfils the contract
return new MutablePropertySources();
}
示例9: getSinglePropertySourcesPlaceholderConfigurer
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() {
// Take care not to cause early instantiation of all FactoryBeans
if (this.beanFactory instanceof ListableBeanFactory) {
ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory;
Map<String, PropertySourcesPlaceholderConfigurer> beans = listableBeanFactory
.getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false,
false);
if (beans.size() == 1) {
return beans.values().iterator().next();
}
}
return null;
}
示例10: properties
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
@Profile("vagrant")
public static PropertySourcesPlaceholderConfigurer properties()
throws Exception {
String file = "application-vagrant.properties";
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
pspc.setLocations(getResources(file));
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setLocalOverride(true);
return pspc;
}
示例11: propertiesForProduction
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
@Profile("production")
public static PropertySourcesPlaceholderConfigurer propertiesForProduction()
throws Exception {
String file = "application-production.properties";
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
pspc.setLocations(getResources(file));
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setLocalOverride(true);
return pspc;
}
示例12: propertiesForDemo
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
@Profile("vagrant-demo")
public static PropertySourcesPlaceholderConfigurer propertiesForDemo()
throws Exception {
String file = "application-vagrant-demo.properties";
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
pspc.setLocations(getResources(file));
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setLocalOverride(true);
return pspc;
}
示例13: propertiesForTest
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
@Profile("test")
public static PropertySourcesPlaceholderConfigurer propertiesForTest()
throws Exception {
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new Resource[]
{new ClassPathResource("application-test.properties")};
pspc.setLocations(resources);
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setLocalOverride(true);
return pspc;
}
示例14: properties
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
public static PropertySourcesPlaceholderConfigurer properties()
{
PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer();
//propertySources.setIgnoreUnresolvablePlaceholders(true);
return propertySources;
}
示例15: properties
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; //导入依赖的package包/类
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =
new PropertySourcesPlaceholderConfigurer();
return propertySourcesPlaceholderConfigurer;
}