List of usage examples for org.springframework.beans.factory.config PropertyPlaceholderConfigurer SYSTEM_PROPERTIES_MODE_FALLBACK
int SYSTEM_PROPERTIES_MODE_FALLBACK
To view the source code for org.springframework.beans.factory.config PropertyPlaceholderConfigurer SYSTEM_PROPERTIES_MODE_FALLBACK.
Click Source Link
From source file:ch.tatool.app.util.ContextUtils.java
/** * Create a new BeanFactory using the main ApplicationContext as parent. * // ww w. j a v a2 s. c om * @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.alfresco.config.SystemPropertiesFactoryBean.java
@SuppressWarnings("unchecked") @Override//w w w . ja va2 s .c o m protected Properties mergeProperties() throws IOException { // First do the default merge Properties props = super.mergeProperties(); // Now resolve all the merged properties if (this.systemPropertiesMode == PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_NEVER) { // If we are in never mode, we don't refer to system properties at all for (String systemProperty : (Set<String>) (Set) props.keySet()) { resolveMergedProperty(systemProperty, props); } } else { // Otherwise, we allow unset properties to drift through from the systemProperties set and potentially set // ones to be overriden by system properties Set<String> propNames = new HashSet<String>((Set<String>) (Set) props.keySet()); propNames.addAll(this.systemProperties); for (String systemProperty : propNames) { resolveMergedProperty(systemProperty, props); if (this.systemPropertiesMode == PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_FALLBACK && props.containsKey(systemProperty)) { // It's already there continue; } // Get the system value and assign if present String systemPropertyValue = System.getProperty(systemProperty); if (systemPropertyValue != null) { props.put(systemProperty, systemPropertyValue); } } } return props; }