use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method formatFieldForAnnotationWithPlaceholders.
@Test
@SuppressWarnings("resource")
public void formatFieldForAnnotationWithPlaceholders() throws Exception {
GenericApplicationContext context = new GenericApplicationContext();
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Properties props = new Properties();
props.setProperty("dateStyle", "S-");
props.setProperty("datePattern", "M-d-yy");
ppc.setProperties(props);
context.getBeanFactory().registerSingleton("ppc", ppc);
context.refresh();
context.getBeanFactory().initializeBean(formattingService, "formattingService");
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
doTestFormatFieldForAnnotation(ModelWithPlaceholders.class, false);
}
use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project cas by apereo.
the class ShibbolethAttributeResolverConfiguration method attributeRepository.
@Bean
public IPersonAttributeDao attributeRepository() {
try {
final PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
final Map<String, Object> result = new HashMap<>();
environment.getPropertySources().forEach(s -> {
if (s instanceof EnumerablePropertySource<?>) {
final EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) s;
Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
}
});
final Properties p = new Properties();
p.putAll(result);
cfg.setProperties(p);
registerBeanIntoApplicationContext(cfg, "shibboleth.PropertySourcesPlaceholderConfigurer");
final ApplicationContext tempApplicationContext = SpringSupport.newContext(getClass().getName(), casProperties.getShibAttributeResolver().getResources(), Collections.singletonList(cfg), Collections.emptyList(), Collections.emptyList(), this.applicationContext);
final Collection<DataConnector> values = BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, DataConnector.class).values();
final Collection<DataConnector> connectors = new HashSet<>(values);
final AttributeResolverImpl impl = new AttributeResolverImpl();
impl.setId(getClass().getSimpleName());
impl.setApplicationContext(tempApplicationContext);
impl.setAttributeDefinitions(BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, AttributeDefinition.class).values());
impl.setDataConnectors(connectors);
if (!impl.isInitialized()) {
impl.initialize();
}
return new ShibbolethPersonAttributeDao(impl);
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return Beans.newStubAttributeRepository(casProperties.getAuthn().getAttributeRepository());
}
use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project cxf by apache.
the class EngineLifecycleTest method setUpBus.
public void setUpBus(boolean includeService) throws Exception {
applicationContext = new GenericApplicationContext();
readBeans(new ClassPathResource("/org/apache/cxf/systest/http_jetty/cxf.xml"));
readBeans(new ClassPathResource("META-INF/cxf/cxf.xml"));
readBeans(new ClassPathResource("jetty-engine.xml", getClass()));
if (includeService) {
readBeans(new ClassPathResource("server-lifecycle-beans.xml", getClass()));
}
// bring in some property values from a Properties file
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
Properties properties = new Properties();
properties.setProperty("staticResourceURL", getStaticResourceURL());
cfg.setProperties(properties);
// now actually do the replacement
cfg.postProcessBeanFactory(applicationContext.getBeanFactory());
applicationContext.refresh();
}
use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project alf.io by alfio-event.
the class TestConfiguration method propConfig.
@Bean
public static PropertyPlaceholderConfigurer propConfig() {
Properties properties = new Properties();
properties.put("alfio.version", "1.9-SNAPSHOT");
properties.put("alfio.build-ts", ZonedDateTime.now(ZoneId.of("UTC")).minusDays(1).toString());
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(out);
properties.list(pw);
pw.flush();
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
ppc.setLocation(new ByteArrayResource(out.toByteArray()));
return ppc;
}
use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project disconf-spring-boot-starter by xjzrc.
the class DisconfAutoConfiguration method disconfPropertyPlaceholderConfigurer.
/**
* 当配置文件改变,不会自动reload到系统
*
* @param factoryBean 不会自动reload配置工厂
* @return PropertyPlaceholderConfigurer
* @throws IOException IOException
*/
@Bean
@ConditionalOnBean(name = "disconfUnReloadablePropertiesFactoryBean")
public PropertyPlaceholderConfigurer disconfPropertyPlaceholderConfigurer(@Qualifier("disconfUnReloadablePropertiesFactoryBean") ReloadablePropertiesFactoryBean factoryBean) throws IOException {
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setOrder(1);
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
configurer.setProperties(factoryBean.getObject());
addPropertiesPropertySource("disconfUnReloadableProperties", factoryBean.getObject());
return configurer;
}
Aggregations