List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setProperties
public void setProperties(Properties properties)
From source file:nz.co.senanque.madura.bundle.BundleRootImpl.java
public void init(DefaultListableBeanFactory ownerBeanFactory, Properties properties, ClassLoader cl, Map<String, Object> inheritableBeans) { m_properties = properties;//from w ww. j a va2 s . c o m m_inheritableBeans = inheritableBeans; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(cl); m_classLoader = cl; GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); String contextPath = properties.getProperty("Bundle-Context", "/bundle-spring.xml"); m_logger.debug("loading context: {}", contextPath); ClassPathResource classPathResource = new ClassPathResource(contextPath, cl); xmlReader.loadBeanDefinitions(classPathResource); PropertyPlaceholderConfigurer p = new PropertyPlaceholderConfigurer(); p.setProperties(properties); ctx.addBeanFactoryPostProcessor(p); if (m_logger.isDebugEnabled()) { dumpClassLoader(cl); } for (Map.Entry<String, Object> entry : inheritableBeans.entrySet()) { BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder .genericBeanDefinition(InnerBundleFactory.class); beanDefinitionBuilder.addPropertyValue("key", entry.getKey()); beanDefinitionBuilder.addPropertyValue("object", inheritableBeans.get(entry.getKey())); ctx.registerBeanDefinition(entry.getKey(), beanDefinitionBuilder.getBeanDefinition()); } Scope scope = ownerBeanFactory.getRegisteredScope("session"); if (scope != null) { ctx.getBeanFactory().registerScope("session", scope); } ctx.refresh(); m_applicationContext = ctx; Thread.currentThread().setContextClassLoader(classLoader); }
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 w w . j a va 2s .co m*/ 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:gov.nih.nci.ncicb.cadsr.bulkloader.util.SpringBeansUtil.java
public void initialize(Properties props) { PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer(); config.setProperties(props); config.postProcessBeanFactory(beanFactory); saveProperties(props);/*ww w. j av a 2 s . co m*/ }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.TestListWrapper.java
protected void setUp() throws Exception { loadJdbcProps();// ww w . j a v a 2 s.c om ClassPathResource resource = new ClassPathResource("viewService.xml"); XmlBeanFactory factory = new XmlBeanFactory(resource); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setSystemPropertiesModeName("SYSTEM_PROPERTIES_MODE_OVERRIDE"); cfg.setProperties(jdbcProps); cfg.postProcessBeanFactory(factory); repo = (RepositoryService) factory.getBean("repoService"); }
From source file:no.dusken.aranea.spring.AraneaContextLoaderListener.java
public void addDeveloperModeReplacer(ConfigurableWebApplicationContext wac) { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); final Properties properties = new Properties(); properties.setProperty("developerMode", Boolean.toString(System.getProperty("developerMode") != null)); configurer.setProperties(properties); configurer.setIgnoreUnresolvablePlaceholders(true); wac.addBeanFactoryPostProcessor(configurer); }
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();//w w w . ja va2 s. com 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:com.google.enterprise.connector.otex.LivelinkConnectorFactory.java
/** * Create a connector instance./* w w w . j a v a2 s . c o m*/ * This conforms to com.google.enterprise.connector.spi.ConnectorFactory * interface for use by validateConfig(). * * @param config Map of configuration properties */ @Override public Connector makeConnector(Map<String, String> config) throws RepositoryException { try { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory); Resource prototype = new ClassPathResource("config/connectorInstance.xml"); beanReader.loadBeanDefinitions(prototype); // Seems non-intuitive to load these in this order, but we want newer // versions of the connectors to override any default bean definitions // specified in old-style monolithic connectorInstance.xml files. Resource defaults = new ClassPathResource("config/connectorDefaults.xml"); if (defaults != null) { beanReader.loadBeanDefinitions(defaults); } // This code should be using setLocation rather than setProperties, but // that requires the machinery of InstanceInfo.getPropertiesResource. PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.putAll(config); cfg.setProperties(props); cfg.postProcessBeanFactory(factory); return (Connector) factory.getBean("Livelink_Enterprise_Server"); } catch (Throwable t) { throw new RepositoryException(t); } }
From source file:org.nebulaframework.util.spring.NebulaApplicationContext.java
/** * Create a new NebulaApplicationContext using the XML file given and * configures the context using the specified {@code Properties}. * /*from w ww .j a va 2 s .co m*/ * @param configLocation * resource location * @param props * @throws BeansException * if context creation failed */ public NebulaApplicationContext(String configLocation, Properties props) throws BeansException { this(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); this.addBeanFactoryPostProcessor(configurer); this.setConfigLocation(configLocation); this.refresh(); this.start(); }
From source file:org.nebulaframework.util.spring.NebulaApplicationContext.java
/** * Create a new NebulaApplicationContext using the XML file given and * configures the context using the specified Property File. * /*from www. ja v a 2s.c om*/ * @param configLocation * resource location * @param propsLocation * property file location * @throws BeansException * if context creation failed */ public NebulaApplicationContext(String configLocation, String propsLocation) throws BeansException, IOException { // Load Properties Properties props = new Properties(); FileInputStream fin = new FileInputStream(propsLocation); props.load(fin); fin.close(); // Create Context PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); this.addBeanFactoryPostProcessor(configurer); this.setConfigLocation(configLocation); this.refresh(); this.start(); }
From source file:org.activiti.crystalball.simulator.TwoEnginesWithoutProcessTest.java
@Test public void test() throws Exception { String tempDir = "target"; FileUtils.copyFile(//from w w w.java 2 s. c o m FileUtils.getFile( new String[] { (new StringBuilder()).append(LIVE_DB).append(".h2.db").toString() }), FileUtils.getFile( new String[] { (new StringBuilder()).append(tempDir).append("/simulationRunDB-aaa-") .append(Thread.currentThread().getId()).append(".h2.db").toString() })); System.setProperty("_SIM_DB_PATH", (new StringBuilder()).append(tempDir).append("/simulationRunDB-aaa-") .append(Thread.currentThread().getId()).toString()); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimRun-h2-context.xml"); PropertyPlaceholderConfigurer propConfig = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("simulationRunId", "simulationRunDB-aaa-" + Thread.currentThread().getId()); propConfig.setProperties(properties); appContext.addBeanFactoryPostProcessor(propConfig); appContext.refresh(); SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); String userId = "user1"; TaskService taskService = (TaskService) appContext.getBean("taskService"); TaskService simTaskService = (TaskService) appContext.getBean("simTaskService"); List<Task> liveTaskList = ((TaskQuery) taskService.createTaskQuery().taskCandidateUser(userId) .orderByTaskPriority().desc()).listPage(0, 1); List<Task> execTaskList = ((TaskQuery) simTaskService.createTaskQuery().taskCandidateUser(userId) .orderByTaskPriority().desc()).listPage(0, 1); Assert.assertTrue(liveTaskList.size() == execTaskList.size()); IdentityService identityService = (IdentityService) appContext.getBean("identityService"); IdentityService simIdentityService = (IdentityService) appContext.getBean("simIdentityService"); List<User> users = identityService.createUserQuery().list(); List<User> simUsers = simIdentityService.createUserQuery().list(); Assert.assertTrue(users.size() == simUsers.size()); simRun.execute(new Date(), null); appContext.close(); }