List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer PropertyPlaceholderConfigurer
PropertyPlaceholderConfigurer
From source file:org.activiti.crystalball.simulator.impl.simulationexecutor.SimulationRunExecuteJobHandler.java
public void execute(JobEntity job, String configuration, SimulationInstanceEntity simulationInstance, CommandContext commandContext) { log.log(Level.INFO, "Starting simulation experiment [" + simulationInstance + "] configuration [" + configuration + "]"); SimulationRunEntity simulationRun = commandContext.getSimulationRunManager() .findSimulationRunWithReferencesById(configuration); SimulationContext.setSimulationRun(simulationRun); //initializeSimulationRun ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( simulationRun.getSimulation().getSimulationConfigUrl()); PropertyPlaceholderConfigurer propConfig = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("simulationRunId", configuration); propConfig.setProperties(properties); appContext.addBeanFactoryPostProcessor(propConfig); appContext.refresh();// www.j av a 2 s. c om SimulationRunHelper runHelper = new NoopSimulationRunHelper(); if (appContext.containsBean("simulationRunHelper")) runHelper = (SimulationRunHelper) appContext.getBean("simulationRunHelper"); try { runHelper.before(configuration); SimulationRun simRun = (SimulationRun) appContext.getBean("simulationRun"); simRun.execute(simulationRun); } catch (Exception e) { log.log(Level.SEVERE, "SimulationRun handling error" + simulationRun, e); } finally { runHelper.after(configuration); appContext.close(); } job.delete(); SimulationContext.removeSimulationRun(); // check whether all jobs for given simulationInstance were already executed. simulationInstance.checkActivity(); log.log(Level.INFO, "finished simulation experiment [" + simulationInstance + "] configuration [" + configuration + "]"); }
From source file:org.intalio.tempo.security.ws.BaseWS.java
protected void initStatics() { if (_initialized) return;/* www .ja v a 2s .com*/ try { synchronized (BaseWS.class) { if (_initialized) return; LOG.debug("Initializing configuration."); String configDir = System.getProperty(Constants.CONFIG_DIR_PROPERTY); if (configDir == null) { throw new RuntimeException( "System property " + Constants.CONFIG_DIR_PROPERTY + " not defined."); } _configDir = new File(configDir); if (!_configDir.exists()) { throw new RuntimeException( "Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist."); } Thread thread = Thread.currentThread(); ClassLoader oldClassLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getClass().getClassLoader()); FileSystemResource config = new FileSystemResource(new File(_configDir, "securityConfig.xml")); XmlBeanFactory factory = new XmlBeanFactory(config); PropertyPlaceholderConfigurer propsCfg = new PropertyPlaceholderConfigurer(); propsCfg.setSearchSystemEnvironment(true); propsCfg.postProcessBeanFactory(factory); _securityProvider = (SecurityProvider) factory.getBean("securityProvider"); _tokenService = (org.intalio.tempo.security.token.TokenService) factory.getBean("tokenService"); _initialized = true; } finally { thread.setContextClassLoader(oldClassLoader); } } } catch (RuntimeException except) { LOG.error("Error during initialization of security service", except); throw except; } }
From source file:com.alejandroszlv.mock.repository.config.RepositoryConfig.java
@Bean public static PropertyPlaceholderConfigurer properties() { PropertyPlaceholderConfigurer properties = new PropertyPlaceholderConfigurer(); ClassPathResource[] resources = new ClassPathResource[] { new ClassPathResource("db.properties") }; properties.setLocations(resources);/* w w w. j a v a 2s . co m*/ properties.setIgnoreUnresolvablePlaceholders(true); return properties; }
From source file:no.dusken.common.plugin.spring.PropertyReplacer.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { ServletContextResourceLoader loader = new ServletContextResourceLoader(servletContext); Properties properties = new Properties(); File file = (File) servletContext.getAttribute(DataDirectoryPropertyReplacer.SERVLET_CONTEXT_ATTR); properties.setProperty("dataDir", file.getAbsolutePath()); List<Resource> resources = new ArrayList<Resource>(); resources.add(loader.getResource("/WEB-INF/" + filename)); /* Check whether dataDir/common.conf exist. If it does add it as a location * Also add /WEB-INF/common.conf, so that if the file doesn't exist use default values *//*from w ww . j av a 2 s. com*/ File configFile = new File(file.getAbsolutePath(), filename); if (configFile.exists()) { resources.add(loader.getResource("file:" + configFile.getAbsolutePath())); } PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocations(resources.toArray(new Resource[resources.size()])); configurer.setProperties(properties); configurer.postProcessBeanFactory(configurableListableBeanFactory); }
From source file:org.openspaces.itest.persistency.cassandra.spring.CassandaraFactoryBeansTest.java
@Test public void test() { final boolean refreshNow = false; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { TEST_FACTORY_XML }, refreshNow); PropertyPlaceholderConfigurer propertyConfigurer = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.setProperty("cassandra.hosts", server.getHost()); properties.setProperty("cassandra.port", String.valueOf(server.getPort())); properties.setProperty("cassandra.keyspace", server.getKeySpaceName()); properties.setProperty("cassandra.user", "default"); properties.setProperty("cassandra.password", "default"); properties.setProperty("cassandra.ds.cluster", "ds_cluster"); properties.setProperty("cassandra.sync.cluster", "sync_cluster"); properties.setProperty("cassandra.ds.minconnections", String.valueOf(1)); properties.setProperty("cassandra.ds.maxconnections", String.valueOf(5)); properties.setProperty("cassandra.ds.batchlimit", String.valueOf(100)); properties.setProperty("cassandra.hector.gcgrace", String.valueOf(60 * 60 * 24 * 10)); properties.setProperty("cassandra.hector.read.consistency.level", CassandraConsistencyLevel.QUORUM.name()); properties.setProperty("cassandra.hector.write.consistency.level", CassandraConsistencyLevel.ONE.name()); propertyConfigurer.setProperties(properties); context.addBeanFactoryPostProcessor(propertyConfigurer); context.refresh();/*w ww. j av a 2s . co m*/ try { syncEndpoint = context.getBean(CassandraSpaceSynchronizationEndpoint.class); dataSource = context.getBean(CassandraSpaceDataSource.class); doWork(); } finally { context.close(); } }
From source file:org.pegadi.webapp.spring.PropertyReplacer.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { ServletContextResourceLoader loader = new ServletContextResourceLoader(servletContext); Properties properties = new Properties(); File file = (File) servletContext.getAttribute(DataDirectoryPropertyReplacer.SERVLET_CONTEXT_ATTR); properties.setProperty("dataDir", file.getAbsolutePath()); List<Resource> resources = new ArrayList<Resource>(); resources.add(loader.getResource("/WEB-INF/pegadi.conf")); /* Check wether dataDir/pegadi.conf exist. If it does add it as a location * Also add /WEB-INF/pegadi.conf, so that if the file doesn't exist use default values *///from www .j a va2 s .c o m File configFile = new File(file.getAbsolutePath(), "pegadi.conf"); if (configFile.exists()) { resources.add(loader.getResource("file:" + configFile.getAbsolutePath())); } PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocations(resources.toArray(new Resource[] {})); configurer.setProperties(properties); configurer.postProcessBeanFactory(configurableListableBeanFactory); }
From source file:de.pksoftware.springstrap.core.config.RootConfigBase.java
/** * Configure PropertyPlaceholderConfigurer. * @return//from w ww . ja v a2 s . co m */ @Bean public PropertyPlaceholderConfigurer propertyPlaceholderConfigurerBean() { logger.info("Creating PPC Bean..."); PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); propertyPlaceholderConfigurer.setLocation(new ClassPathResource(getPropertyFileName())); //propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true); //propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true); return propertyPlaceholderConfigurer; //ClassPathResource[] resources = new ClassPathResource[ ] // { new ClassPathResource( getPropertyFileName() ) }; }
From source file:org.cagrid.identifiers.namingauthority.util.SecurityUtil.java
public static void addAdmin(String naConfigurationFile, String naProperties, String adminUser) throws InvalidIdentifierException, URISyntaxException, NamingAuthorityConfigurationException, NamingAuthoritySecurityException, InvalidIdentifierValuesException { FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile); FileSystemResource naPropertiesResource = new FileSystemResource(naProperties); XmlBeanFactory factory = new XmlBeanFactory(naConfResource); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(naPropertiesResource); cfg.postProcessBeanFactory(factory); NamingAuthorityImpl na = (NamingAuthorityImpl) factory.getBean("NamingAuthority", MaintainerNamingAuthority.class); na.getIdentifierDao().createInitialAdministrator(adminUser); // KeyData kd = na.getKeyData(null, na.getSystemIdentifier(), Keys.ADMIN_USERS); // if (kd == null) { // System.err.println("KD IS NULL"); // kd = new KeyData(); // }//from ww w. j a va 2 s . c o m // // List<String> values = kd.getValues(); // if (values == null) { // System.err.println("VALUES IS NULL"); // values = new ArrayList<String>(); // } // // if (values.contains(adminUser)) { // throw new NamingAuthorityConfigurationException("Provided identity [" + adminUser + "] is already an administrator"); // } // // values.add(adminUser); // // IdentifierValues ivalues = new IdentifierValues(); // ivalues.put(Keys.ADMIN_USERS, kd); // na.replaceKeys(null, na.getSystemIdentifier(), ivalues); }
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; }
From source file:exercise.cca.data.cli.main.MainCli.java
protected static ConfigurableApplicationContext loadContext(final String contextPath) { final GenericApplicationContext ctx = new GenericApplicationContext(); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource(contextPath)); final PropertyPlaceholderConfigurer placeholderProcessor = new PropertyPlaceholderConfigurer(); ctx.addBeanFactoryPostProcessor(placeholderProcessor); ctx.refresh();//from ww w . ja v a 2s. c om return ctx; }