List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer PropertyPlaceholderConfigurer
PropertyPlaceholderConfigurer
From source file:ch.tatool.app.util.ContextUtils.java
/** * Create a new BeanFactory using the main ApplicationContext as parent. * /*from w w w . j a va 2 s . c o m*/ * @param classpath the path to the bean definition file in the classpath * @param properties set of properties that should be replaced in the definitions * @return a BeanFactory instance */ public static BeanFactory createBeanFactory(String classpath, Properties properties) { // create an empty bean factory DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); // load the context file - has to be done here, otherwise properties won't get resolved XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); Resource resource = new ClassPathResource(classpath); reader.loadBeanDefinitions(resource); // apply the properties to the context PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(properties); configurer.setIgnoreUnresolvablePlaceholders(false); configurer.setIgnoreResourceNotFound(false); configurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK); configurer.postProcessBeanFactory(beanFactory); return beanFactory; }
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 w w. j av a 2 s. c om 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.alfresco.cacheserver.dropwizard.Application.java
/** * Creates a Spring property place holder configurer for use in a Spring context * from the given file path.//from w w w . ja v a 2 s . c o m * * @param springPropsFileName * @return the Spring property place holder configurer * @throws IOException */ protected PropertyPlaceholderConfigurer loadSpringConfigurer(String yamlConfigFileLocation) throws IOException { if (StringUtils.isEmpty(yamlConfigFileLocation)) { throw new IllegalArgumentException("Config file location must not be empty"); } logger.debug("Loading properties from '" + yamlConfigFileLocation + "'"); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocation(new FileSystemResource(yamlConfigFileLocation)); configurer.setPropertiesPersister(new YamlPropertiesPersister()); return configurer; }
From source file:org.pmedv.core.util.ResourceUtils.java
/** * Configures a factory from a properties file read from an input stream * /* ww w . j a va2 s. co m*/ * @param is the stream to read the properties from * @param factory the factory to configure */ public static Properties configureFactoryFromInputStream(InputStream is, XmlBeanFactory factory) { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); Properties p = new Properties(); try { p.load(is); } catch (IOException e) { e.printStackTrace(); } cfg.setProperties(p); cfg.postProcessBeanFactory(factory); return p; }
From source file:io.pivotal.gemfire.main.SpringGemFireServerApplication.java
@Bean
PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
return new PropertyPlaceholderConfigurer();
}
From source file:il.ac.tau.yoavram.pes.SpringRunner.java
public static void run(String[] args) throws IOException { System.out.println("Starting " + SpringRunner.class.getSimpleName()); SimulationConfigurer configurer = new SimulationConfigurer(args); if (configurer.getSpringXmlConfig() == null) { System.err.println("Spring XML config file not defined"); System.err.println();/*w w w.j a v a 2 s .c o m*/ System.exit(1); } if (configurer.getProperties() == null) { System.err.println("Properties not defined"); System.err.println(); System.exit(1); } // get the properties Properties properties = configurer.getProperties(); String jobName = properties.getProperty(SimulationConfigurer.JOB_NAME_KEY); // create context AbstractXmlApplicationContext context = new ClassPathXmlApplicationContext(); // add properties to context logger.info("Adding properties to context: " + properties.toString()); PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); propertyPlaceholderConfigurer.setProperties(properties); context.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer); // set config location String configLocation = configurer.getSpringXmlConfig().toString(); logger.info("Loading context from file " + configLocation); context.setConfigLocation(configLocation); // make sure destroy methods will be called and refresh the context context.registerShutdownHook(); context.refresh(); // persist properties try { PropertiesPersister persister = context.getBean(PropertiesPersister.class); if (persister != null) { persister.persist(properties); } } catch (NoSuchBeanDefinitionException e) { // nothing to do } // get the simulation bean and run it Simulation simulation = context.getBean("simulation", Simulation.class); logger.debug("Starting simulation " + jobName); simulation.start(); }
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 w w .j a va2s. 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: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:me.philnate.textmanager.config.cfgMongo.java
@Bean public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { PropertyPlaceholderConfigurer config = new PropertyPlaceholderConfigurer(); config.setLocation(new ClassPathResource("git.properties")); return config; }
From source file:org.consultjr.mvc.core.config.ApplicationConfig.java
@Bean public static PropertyPlaceholderConfigurer setupPropertyConfigurer() { return new PropertyPlaceholderConfigurer(); }