Search in sources :

Example 1 with PropertyPlaceholderConfigurer

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);
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) JodaDateTimeFormatAnnotationFormatterFactory(org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with PropertyPlaceholderConfigurer

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());
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) HashMap(java.util.HashMap) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Properties(java.util.Properties) ApplicationContext(org.springframework.context.ApplicationContext) ShibbolethPersonAttributeDao(org.apereo.cas.persondir.support.ShibbolethPersonAttributeDao) AttributeResolverImpl(net.shibboleth.idp.attribute.resolver.impl.AttributeResolverImpl) DataConnector(net.shibboleth.idp.attribute.resolver.DataConnector) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean)

Example 3 with PropertyPlaceholderConfigurer

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();
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 4 with PropertyPlaceholderConfigurer

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;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) PrintWriter(java.io.PrintWriter) Bean(org.springframework.context.annotation.Bean)

Example 5 with PropertyPlaceholderConfigurer

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;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) ReloadingPropertyPlaceholderConfigurer(com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) DisconfMgrBean(com.baidu.disconf.client.DisconfMgrBean) ReloadablePropertiesFactoryBean(com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PropertyPlaceholderConfigurer (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer)19 Bean (org.springframework.context.annotation.Bean)12 ClassPathResource (org.springframework.core.io.ClassPathResource)8 Properties (java.util.Properties)6 Resource (org.springframework.core.io.Resource)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 Test (org.junit.Test)2 DisconfMgrBean (com.baidu.disconf.client.DisconfMgrBean)1 ReloadablePropertiesFactoryBean (com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean)1 ReloadingPropertyPlaceholderConfigurer (com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer)1 SpringPropertyInjectSupport (com.jim.framework.configcenter.spring.SpringPropertyInjectSupport)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1