Example usage for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setProperties

List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setProperties

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setProperties.

Prototype

public void setProperties(Properties properties) 

Source Link

Document

Set local properties, e.g.

Usage

From source file:com.centeractive.ws.server.core.SoapServer.java

private void configureParentContext() {
    PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer();
    config.setProperties(buildProperties());
    context = new ClassPathXmlApplicationContext();
    context.addBeanFactoryPostProcessor(config);
    context.setConfigLocation(SPRING_CONTEXT_LOCATION);
    context.refresh();/* ww  w  .  ja  v a2s.  co  m*/
    context.registerShutdownHook();
    server = context.getBean(SERVER_BEAN_NAME, Server.class);
}

From source file:org.pentaho.pat.plugin.PatLifeCycleListener.java

public void loaded() throws PluginLifecycleException {
    ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader();
    IServiceManager serviceManager = (IServiceManager) PentahoSystem.get(IServiceManager.class,
            PentahoSessionHolder.getSession());
    try {/*from  w  ww  .  ja  va 2  s  . c om*/
        sessionBean = (SessionServlet) serviceManager.getServiceBean("gwt", "session.rpc"); //$NON-NLS-1$
        queryBean = (QueryServlet) serviceManager.getServiceBean("gwt", "query.rpc"); //$NON-NLS-1$
        discoveryBean = (DiscoveryServlet) serviceManager.getServiceBean("gwt", "discovery.rpc"); //$NON-NLS-1$
        platformBean = (PlatformServlet) serviceManager.getServiceBean("gwt", "platform.rpc"); //$NON-NLS-1$

        final IPluginManager pluginManager = (IPluginManager) PentahoSystem.get(IPluginManager.class,
                PentahoSessionHolder.getSession());
        final PluginClassLoader pluginClassloader = (PluginClassLoader) pluginManager
                .getClassLoader(PAT_PLUGIN_NAME);
        final String hibernateConfigurationFile = PentahoSystem
                .getSystemSetting("hibernate/hibernate-settings.xml", "settings/config-file", null); //$NON-NLS-1$
        final String pentahoHibConfigPath = PentahoSystem.getApplicationContext()
                .getSolutionPath(hibernateConfigurationFile);

        if (pluginClassloader == null)
            throw new ServiceException(Messages.getString("LifeCycleListener.NoPluginClassloader")); //$NON-NLS-1$

        Thread.currentThread().setContextClassLoader(pluginClassloader);
        final URL contextUrl = pluginClassloader.getResource(PAT_APP_CONTEXT);
        final URL patHibConfigUrl = pluginClassloader.getResource(PAT_HIBERNATE_CONFIG);
        final URL patPluginPropertiesUrl = pluginClassloader.getResource(PAT_PLUGIN_PROPERTIES);
        if (patHibConfigUrl == null)
            throw new ServiceException("File not found: PAT Hibernate Config : " + PAT_HIBERNATE_CONFIG);
        else
            LOG.debug(PAT_PLUGIN_NAME + ": PAT Hibernate Config:" + patHibConfigUrl.toString());

        if (patPluginPropertiesUrl == null)
            throw new ServiceException("File not found: PAT Plugin properties : " + PAT_PLUGIN_PROPERTIES);
        else
            LOG.debug(PAT_PLUGIN_NAME + ": PAT Plugin Properties:" + patPluginPropertiesUrl.toString());

        if (contextUrl != null) {
            String appContextUrl = contextUrl.toString();
            final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                    new String[] { appContextUrl }, false);
            applicationContext.setClassLoader(pluginClassloader);
            applicationContext.setConfigLocation(appContextUrl);
            applicationContext.setAllowBeanDefinitionOverriding(true);

            final Configuration pentahoHibConfig = new Configuration();
            pentahoHibConfig.configure(new File(pentahoHibConfigPath));

            final AnnotationConfiguration patHibConfig = new AnnotationConfiguration();
            patHibConfig.configure(patHibConfigUrl);

            Properties properties = new Properties();
            properties.load(pluginClassloader.getResourceAsStream(PAT_PLUGIN_PROPERTIES));
            String hibernateDialectCfg = (String) properties.get("pat.plugin.datasource.hibernate.dialect");
            String hibernateDialect = null;
            if (StringUtils.isNotBlank(hibernateDialectCfg)) {
                if (hibernateDialectCfg.equals("auto")) {
                    hibernateDialect = pentahoHibConfig.getProperty("dialect");
                } else {
                    hibernateDialect = hibernateDialectCfg;
                }
            }

            if (StringUtils.isNotBlank(hibernateDialect)) {
                patHibConfig.setProperty("hibernate.dialect", hibernateDialect);
                LOG.info(PAT_PLUGIN_NAME + " : using hibernate dialect: " + hibernateDialect);
            }

            String dataSourceType = (String) properties.get("pat.plugin.datasource.type");
            String datasourceResource = null;
            if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jdbc")) {
                datasourceResource = PAT_DATASOURCE_JDBC;
                LOG.info(PAT_PLUGIN_NAME + " : using JDBC connection");

            }
            if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jndi")) {
                datasourceResource = PAT_DATASOURCE_JNDI;
                LOG.info(PAT_PLUGIN_NAME + " : using JNDI : " + (String) properties.get("jndi.name"));
            }

            XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(datasourceResource));
            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
            cfg.setLocation(new ClassPathResource(PAT_PLUGIN_PROPERTIES));
            cfg.postProcessBeanFactory(factory);

            XmlBeanFactory bfSession = new XmlBeanFactory(new ClassPathResource(PAT_SESSIONFACTORY), factory);

            PropertyPlaceholderConfigurer cfgSession = new PropertyPlaceholderConfigurer();
            cfgSession.setProperties(patHibConfig.getProperties());
            cfgSession.postProcessBeanFactory(bfSession);

            ClassPathXmlApplicationContext tmpCtxt = new ClassPathXmlApplicationContext();
            tmpCtxt.refresh();
            DefaultListableBeanFactory tmpBf = (DefaultListableBeanFactory) tmpCtxt.getBeanFactory();

            tmpBf.setParentBeanFactory(bfSession);

            applicationContext.setClassLoader(pluginClassloader);
            applicationContext.setParent(tmpCtxt);
            applicationContext.refresh();

            sessionBean.setStandalone(true);
            SessionServlet.setApplicationContext(applicationContext);
            sessionBean.init();

            queryBean.setStandalone(true);
            QueryServlet.setApplicationContext(applicationContext);
            queryBean.init();

            discoveryBean.setStandalone(true);
            DiscoveryServlet.setApplicationContext(applicationContext);
            discoveryBean.init();

            platformBean.setStandalone(true);
            PlatformServlet.setApplicationContext(applicationContext);
            platformBean.init();

            injectPentahoXmlaUrl();
        } else {
            throw new Exception(Messages.getString("LifeCycleListener.AppContextNotFound"));
        }

    } catch (ServiceException e1) {
        LOG.error(e1.getMessage(), e1);
    } catch (ServletException e) {
        LOG.error(e.getMessage(), e);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    } finally {
        // reset the classloader of the current thread
        if (origContextClassloader != null) {
            Thread.currentThread().setContextClassLoader(origContextClassloader);
        }
    }
}

From source file:org.reficio.ws.server.core.SoapServer.java

private void configureParentContext() {
    PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer();
    config.setProperties(buildProperties());
    context = new ClassPathXmlApplicationContext();
    context.addBeanFactoryPostProcessor(config);
    context.setConfigLocation(SoapServerConstants.SPRING_CONTEXT_LOCATION);
    context.refresh();//from   w  w  w.j av  a  2s.c  om
    context.registerShutdownHook();
    server = context.getBean(SoapServerConstants.SERVER_BEAN_NAME, Server.class);
}

From source file:org.araneaframework.ioc.spring.SimpleAraneaSpringDispatcherServlet.java

public void init() throws ServletException {
    beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    rootConf = new XmlBeanFactory(
            new ClassPathResource("spring-property-conf/property-custom-webapp-aranea-conf.xml"), beanFactory);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(new ClassPathResource("spring-property-conf/default-aranea-conf.properties"));

    Properties localConf = new Properties();
    try {//  w ww .ja  v  a  2s. c o m
        if (getServletContext().getResource("/WEB-INF/aranea-conf.properties") != null)
            localConf.load(getServletContext().getResourceAsStream("/WEB-INF/aranea-conf.properties"));
    } catch (IOException e) {
        throw new ServletException(e);
    }
    cfg.setProperties(localConf);
    cfg.setLocalOverride(true);

    cfg.postProcessBeanFactory(rootConf);

    super.init();
}

From source file:org.drools.container.spring.beans.persistence.VariablePersistenceStrategyTest.java

@Before
public void createSpringContext() {
    try {//  ww w  .java  2 s . co  m
        log.info("creating spring context");
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        Properties properties = new Properties();
        properties.setProperty("temp.dir", TMPDIR);
        configurer.setProperties(properties);
        ctx = new ClassPathXmlApplicationContext();
        ctx.addBeanFactoryPostProcessor(configurer);
        ctx.setConfigLocation("org/drools/container/spring/beans/persistence/beansVarPersistence.xml");
        ctx.refresh();
    } catch (Exception e) {
        log.error("can't create spring context", e);
        throw new RuntimeException(e);
    }
}

From source file:com.github.ffremont.microservices.springboot.node.tasks.SimpleTestConfiguration.java

@Bean
public PropertyPlaceholderConfigurer getProps() throws IOException {
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    Properties props = new Properties();
    Map myMap = new HashMap<>();

    myMap.put("app.base", Files.createTempDirectory("appBaseNode").toString());
    myMap.put("app.cluster", "myCuster");
    myMap.put("app.node", "myNode");
    myMap.put("app.master.host", "localhost");
    myMap.put("app.master.port", "9999");
    myMap.put("app.master.contextRoot", "/test");

    myMap.put("app.master.user", "");
    myMap.put("app.master.pwd", "");
    props.putAll(myMap);/*from ww  w  .  j  a v a 2s.  co  m*/

    configurer.setProperties(props);
    return configurer;
}

From source file:org.openspaces.itest.persistency.cassandra.archive.CassandaraArchiveOperationHandlerTest.java

private void xmlTest(String relativeXmlName) {

    final boolean refreshNow = false;
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { relativeXmlName }, refreshNow);

    PropertyPlaceholderConfigurer propertyConfigurer = new PropertyPlaceholderConfigurer();
    Properties properties = new Properties();
    properties.put("cassandra.keyspace", server.getKeySpaceName());
    properties.put("cassandra.hosts", server.getHost());
    properties.put("cassandra.port", "" + server.getPort());
    properties.put("cassandra.write-consistency", "ALL");
    propertyConfigurer.setProperties(properties);
    context.addBeanFactoryPostProcessor(propertyConfigurer);
    context.refresh();//  w ww .ja  va 2  s. c o  m

    try {
        final CassandraArchiveOperationHandler archiveHandler = context
                .getBean(CassandraArchiveOperationHandler.class);
        Assert.assertEquals(CassandraConsistencyLevel.ALL, archiveHandler.getWriteConsistency());
        final GigaSpace gigaSpace = context.getBean(org.openspaces.core.GigaSpace.class);
        test(archiveHandler, gigaSpace);
    } finally {
        context.close();
    }
}

From source file:org.drools.container.spring.beans.persistence.JPASingleSessionCommandServiceFactoryTest.java

@Before
public void createSpringContext() {
    try {/*ww  w .ja v  a  2 s  .  c o m*/
        log.info("creating spring context");
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        Properties properties = new Properties();
        properties.setProperty("temp.dir", TMPDIR);
        configurer.setProperties(properties);
        ctx = new ClassPathXmlApplicationContext();
        ctx.addBeanFactoryPostProcessor(configurer);
        ctx.setConfigLocation("org/drools/container/spring/beans/persistence/beans.xml");
        ctx.refresh();
    } catch (Exception e) {
        log.error("can't create spring context", e);
        throw new RuntimeException(e);
    }
}

From source file:org.spring.data.gemfire.config.GemFireConfiguration.java

@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();

    Properties placeholders = new Properties();
    placeholders.setProperty("app.gemfire.defaults.region.eviction.threshold", "4096");
    placeholders.setProperty("app.gemfire.defaults.region.partition.local-max-memory", "16384");
    placeholders.setProperty("app.gemfire.defaults.region.partition.total-max-memory", "32768");

    // NOTE ideally, "placeholder" properties used by Spring's Configurer would be externalized in order to
    // avoid re-compilation on property value changes (this is just an example)!
    propertyPlaceholderConfigurer.setProperties(placeholders);

    return propertyPlaceholderConfigurer;
}

From source file:org.spring.data.gemfire.app.context.config.PeerCacheConfiguration.java

@Bean
public PropertyPlaceholderConfigurer gemfireApplicationSettings() {
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();

    Properties placeholders = new Properties();
    placeholders.setProperty("app.gemfire.region.eviction.threshold", "50");
    placeholders.setProperty("app.gemfire.region.entry.expiration.timeout", "120000");
    placeholders.setProperty("app.gemfire.region.partition.local-max-memory", "1024000");
    placeholders.setProperty("app.gemfire.region.partition.total-max-memory", "81920000");

    // NOTE ideally, "placeholder" properties used by Spring's Configurer would be externalized in order to
    // avoid re-compilation on property value changes (this is just an example)!
    propertyPlaceholderConfigurer.setProperties(placeholders);

    return propertyPlaceholderConfigurer;
}