Search in sources :

Example 16 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project tutorials by eugenp.

the class PropertiesWithPlaceHolderConfigurer method propertyConfigurer.

@Bean
public PropertyPlaceholderConfigurer propertyConfigurer() {
    final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
    props.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK);
    return props;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) Bean(org.springframework.context.annotation.Bean)

Example 17 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project tutorials by eugenp.

the class ChildConfig2 method configurer.

@Bean
public static PropertyPlaceholderConfigurer configurer() {
    final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setLocations(new ClassPathResource("child.properties"));
    return ppc;
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean)

Example 18 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project symmetric-ds by JumpMind.

the class ClientSymmetricEngine method init.

@Override
protected void init() {
    try {
        LogSummaryAppenderUtils.registerLogSummaryAppender();
        super.init();
        this.dataSource = platform.getDataSource();
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        configurer.setProperties(parameterService.getAllParameters());
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(springContext);
        ctx.addBeanFactoryPostProcessor(configurer);
        List<String> extensionLocations = new ArrayList<String>();
        extensionLocations.add("classpath:/symmetric-ext-points.xml");
        if (registerEngine) {
            extensionLocations.add("classpath:/symmetric-jmx.xml");
        }
        String xml = parameterService.getString(ParameterConstants.EXTENSIONS_XML);
        File file = new File(parameterService.getTempDirectory(), "extension.xml");
        FileUtils.deleteQuietly(file);
        if (isNotBlank(xml)) {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setValidating(false);
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                // the "parse" method also validates XML, will throw an exception if misformatted
                builder.parse(new InputSource(new StringReader(xml)));
                FileUtils.write(file, xml, false);
                extensionLocations.add("file:" + file.getAbsolutePath());
            } catch (Exception e) {
                log.error("Invalid " + ParameterConstants.EXTENSIONS_XML + " parameter.");
            }
        }
        try {
            ctx.setConfigLocations(extensionLocations.toArray(new String[extensionLocations.size()]));
            ctx.refresh();
            this.springContext = ctx;
            ((ClientExtensionService) this.extensionService).setSpringContext(springContext);
            this.extensionService.refresh();
        } catch (Exception ex) {
            log.error("Failed to initialize the extension points.  Please fix the problem and restart the server.", ex);
        }
    } catch (RuntimeException ex) {
        destroy();
        throw ex;
    }
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ArrayList(java.util.ArrayList) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) File(java.io.File) ClientExtensionService(org.jumpmind.symmetric.service.impl.ClientExtensionService)

Example 19 with PropertyPlaceholderConfigurer

use of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in project cxf by apache.

the class JsHttpRequestTest method additionalSpringConfiguration.

public void additionalSpringConfiguration(GenericApplicationContext applicationContext) throws Exception {
    // 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());
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) Properties(java.util.Properties)

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