List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer setProperties
public void setProperties(Properties properties)
From source file:com.google.enterprise.connector.filenet4.FileNetConnectorFactory.java
/** * Creates a connector instance by loading the bean definitions and creating * the connector bean instance using Spring * * * @see com.google.enterprise.connector.spi.ConnectorFactory#makeConnector(java.util.Map) **//*from w ww .j a v a 2 s. c o m*/ @Override public Connector makeConnector(Map<String, String> config) throws RepositoryException { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory); Resource connectorInstanceConfig = new ClassPathResource(CONNECTOR_DEFAULTS_XML); Resource connectorDefaultsConfig = new ClassPathResource(CONNECTOR_INSTANCE_XML); beanReader.loadBeanDefinitions(connectorInstanceConfig); beanReader.loadBeanDefinitions(connectorDefaultsConfig); Properties props = new Properties(); props.putAll(config); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); configurer.postProcessBeanFactory(factory); Connector connector = (Connector) factory.getBean("Filenet_P8"); if (connector == null) { throw new RepositoryException("Filenet_P8 bean could not be loaded"); } return connector; }
From source file:com.google.enterprise.connector.filesystem.ConfigTest.java
public void testInstantiation() { Properties props = new Properties(); props.putAll(goodConfig);//from w w w . ja v a 2 s.com DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); // Refer to InstanceInfo.makeConnectorWithSpring //(com.google.enterprise.connector.instantiator) for more info on how // these files are loaded to instantiate connector. reader.loadBeanDefinitions(new ClassPathResource(DEFAULTS_CONFIG_FILE, ConfigTest.class)); reader.loadBeanDefinitions(new ClassPathResource(INSTANCE_CONFIG_FILE, ConfigTest.class)); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setProperties(props); cfg.postProcessBeanFactory(beanFactory); String[] beans = beanFactory.getBeanNamesForType(Connector.class); assertEquals(1, beans.length); Object obj = beanFactory.getBean(beans[0]); assertTrue("Expecting instance of Connector interface but the actual " + "instance: " + obj.getClass().toString(), obj instanceof Connector); }
From source file:com.google.enterprise.connector.db.MockDBConnectorFactory.java
/** * Creates a database connector.//from w w w. j ava 2 s . c o m * * @param config map of configuration values. */ /* TODO(jlacey): Extract the Spring instantiation code in CM. */ @Override public Connector makeConnector(Map<String, String> config) throws RepositoryException { // TODO(jlacey): The placeholder values are in the EPPC bean in // connectorDefaults.xml, but we're not loading that, and doing so // would unravel a ball of string: using setLocation instead of // setProperties (since the EPPC bean already has properties), // which in turn requires the ByteArrayResource machinery in // InstanceInfo or writing the properties to a file. Properties props = new Properties(); for (String configKey : DBConnectorType.CONFIG_KEYS) { props.put(configKey, ""); } // Escape MyBatis syntax that looks like a Spring placeholder. // See https://jira.springsource.org/browse/SPR-4953 props.put("docIds", "#{'$'}{docIds}"); props.putAll(config); Resource prototype = new ClassPathResource("config/connectorInstance.xml", MockDBConnectorFactory.class); Resource defaults = new ClassPathResource("config/connectorDefaults.xml", MockDBConnectorFactory.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory); try { beanReader.loadBeanDefinitions(prototype); beanReader.loadBeanDefinitions(defaults); } catch (BeansException e) { throw new RepositoryException(e); } PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setProperties(props); cfg.postProcessBeanFactory(factory); String[] beanList = factory.getBeanNamesForType(DiffingConnector.class); Assert.assertEquals(Arrays.asList(beanList).toString(), 1, beanList.length); return (Connector) factory.getBean(beanList[0]); }
From source file:guru.qas.martini.jmeter.config.DefaultApplicationContextBuilder.java
protected void setEnvironment(ConfigurableApplicationContext context, Properties properties) { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(properties); configurer.setLocalOverride(true);//ww w.j a va2s . c o m configurer.setSearchSystemEnvironment(true); configurer.setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_FALLBACK); context.addBeanFactoryPostProcessor(configurer); }
From source file:com.retroduction.carma.application.CarmaDriverSetup.java
public void init() { GenericApplicationContext newAppContext = new GenericApplicationContext(this.parentContext); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(newAppContext); for (String res : this.beanDefinitionResources) { xmlReader.loadBeanDefinitions(res); }//from ww w .j a v a 2s .c om PropertyPlaceholderConfigurer customerPropsProcessor = new PropertyPlaceholderConfigurer(); customerPropsProcessor.setProperties(this.configurationParameters); newAppContext.addBeanFactoryPostProcessor(customerPropsProcessor); newAppContext.refresh(); newAppContext.registerShutdownHook(); this.appContext = newAppContext; }
From source file:ch.vorburger.mariadb4j.tests.springframework.MariaDB4jSpringServiceTestSpringConfiguration.java
@Bean PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); configureProperties(properties);// ww w .j a va 2 s . co m ppc.setProperties(properties); return ppc; }
From source file:com.notemyweb.config.MainConfig.java
@Bean public PropertyPlaceholderConfigurer createPlaceHolders() throws Exception { PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); Properties properties = new FusionConfig().getFusionProperties(NotesUtil.getEnv()); propertyPlaceholderConfigurer.setProperties(properties); propertyPlaceholderConfigurer/*w ww. j av a 2 s . c om*/ .setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE); return propertyPlaceholderConfigurer; }
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 w ww . ja va2s . 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:org.iternine.jeppetto.testsupport.TestContext.java
public TestContext(String configurationFilename, String propertiesFilename, DatabaseProvider... databaseProviders) { XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(new ClassPathResource(configurationFilename)); xmlBeanFactory.setBeanClassLoader(this.getClass().getClassLoader()); Properties properties = new Properties(); try {//w w w.j a v a 2 s .c o m properties.load(new ClassPathResource(propertiesFilename).getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } if (databaseProviders != null) { for (DatabaseProvider databaseProvider : databaseProviders) { properties = databaseProvider.modifyProperties(properties); } } PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(properties); configurer.postProcessBeanFactory(xmlBeanFactory); try { applicationContext = new GenericApplicationContext(xmlBeanFactory); applicationContext.refresh(); if (databaseProviders != null) { for (DatabaseProvider databaseProvider : databaseProviders) { databases.add(databaseProvider.getDatabase(properties, applicationContext)); } } } catch (RuntimeException e) { if (databaseProviders != null) { for (DatabaseProvider databaseProvider : databaseProviders) { if (databaseProvider instanceof Closeable) { try { ((Closeable) databaseProvider).close(); } catch (IOException e1) { // ignore } } } } throw e; } }
From source file:net.dfs.remote.main.ClientServicesStarter.java
public final void loadNode() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props); context.addBeanFactoryPostProcessor(configurer); context.setConfigLocation("net\\dfs\\remote\\filestorage\\spring-client.xml"); context.refresh();//from ww w . j a v a 2s . c om context.start(); /* FileLocationTrackerImpl hash = new FileLocationTrackerImpl(); hash.removeAll(); */ log.info("Client Started"); FileReceiverSupport receiveFile = (FileReceiverSupport) context.getBean("receiveFile"); receiveFile.connectJavaSpace(); receiveFile.retrieveFile(); }