PropertyPlaceholderConfigurer doesnt load properties with applicationContext
Hi,
I try to use the PropertyPlaceholderConfigurer.postProcessBeanFacto ry() method, but it doesn't seems to work with the properties object setProperties().
Code:
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
ResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource("classpath:default.properties");
Properties properties = new Properties();
prop.load(resource.getInputStream());
configurer.setProperties(properties);
configurer.postProcessBeanFactory(context.getBeanFactory());
In my log nothing appear....
But if i use the setLocation() it works
Code:
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
ResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource("classpath:default.properties");
configurer.setLocation(resource);
configurer.postProcessBeanFactory(context.getBeanFactory());
Quote:
18:19:40,129 INFO PropertyPlaceholderConfigurer:174 - Loading properties file from class path resource [default.properties]
Somebody have noticed that before - It is a bug ?
I use spring 2.5
I really need an applicationContext class for the shutdownHook(), i cannot use the XmlBeanFactory (i use the properties object and it works).
if i use the XMLBeanFactory with setProperties() it's working :
Code:
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
factory = new XmlBeanFactory(new ClassPathResource(applicationContextFile));
ResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource("classpath:default.properties");
Properties properties = new Properties();
prop.load(resource.getInputStream());
configurer.setProperties(properties);
configurer.postProcessBeanFactory(factory);
Example with ClassPathXmlApplicationContext
Here is an example of code
Code:
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
configurer.setLocation(new ClassPathResource("context.properties"));
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}, false);
applicationContext.addBeanFactoryPostProcessor(configurer);
applicationContext.refresh();