本文整理匯總了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;
}