final DefaultListableBeanFactory beanFactory = createBeanFactory();
final GenericApplicationContext context = new GenericApplicationContext(beanFactory);
context.registerShutdownHook();
final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
propertyPlaceholderConfigurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
if (properties != null) {
if (properties instanceof Resource)
propertyPlaceholderConfigurer.setLocation((Resource) properties);
else if (properties instanceof Properties)
propertyPlaceholderConfigurer.setProperties((Properties) properties);
else
throw new IllegalArgumentException("Properties argument - " + properties + " - is of an unhandled type");
}
context.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);