View Full Version : Use of the PropertyPlaceholderConfigurer within a WebContext
awerner
Aug 22nd, 2004, 03:29 PM
Hi,
i tried to use the PropertyPlaceholderConfigurer on a WebApplicationContext, but the replacement failed.
I used the following code:
PropertyPlaceholderConfigurer lConfigurer = null;
ApplicationContext lApplicationContext = null;
ConfigurableListableBeanFactory beanFactory = null;
Properties lProperties = null;
...
lApplicationContext = WebApplicationContextUtils.getWebApplicationContex t(
pRequestContext.getServlet().getServletContext());
lConfigurer = new PropertyPlaceholderConfigurer();
lConfigurer.setProperties(lProperties);
beanFactory = ((AbstractApplicationContext) lApplicationContext).getBeanFactory();
lConfigurer.postProcessBeanFactory(beanFactory);
Any ideas on whats going wrong/i did wrong are appreciated.
Regards,
Andreas Werner
Colin Sampaleanu
Aug 22nd, 2004, 05:33 PM
You should be using it declaratively, since the application context has long since been created by the time you are trying to use the configurer on it. This is described here:
http://www.springframework.org/docs/reference/beans.html#beans-context-placeholderconfigurer
Regards,
awerner
Aug 23rd, 2004, 07:59 AM
Thanks for the hint, now it works.
Regards,
Andreas Werner
FLM_25
Mar 25th, 2008, 01:03 PM
Hi,
I have the same problem (In Spring 2.0.4), but your link is brokken.
I use a webApplication like this :
private IFrontalService frontalService = null;
protected WebApplicationContext wac = null;
/* (non-Javadoc)
* @see org.apache.struts.action.Action#setServlet(org.apa che.struts.action.ActionServlet)
*/
public void setServlet(ActionServlet actionServlet) {
super.setServlet(actionServlet);
if (actionServlet != null) {
ServletContext servletContext = actionServlet.getServletContext();
this.wac = WebApplicationContextUtils
.getWebApplicationContext(servletContext);
this.frontalService = (IFrontalService) wac.getBean("frontalService");
}
}
and a spring configuration :
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="locations">
<list>
<value>classpath:frontal.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders"><value>true</value></property>
</bean>
<bean id="frontalService"
class="com.mypack.app.frontal.service.FrontalService">
<property name="wrapper">
<ref bean="wrapperTarget" />
</property>
<property name="urlBpm"><value>${url.wsdl.bpm}</value></property>
</bean>
My property file
url.wsdl.bpm = http://localhost:8080/APP-BPM/services/ExecutionManager?wsdl
In the "setServlet" method, when i get the bean "frontalService", the value of "urlBpm" is "${url.wsdl.bpm}".
Spring doesn't get the real value in my property file.
Is there a solution ?
Thanks
Bron
Mar 25th, 2008, 04:22 PM
Is the properties file being found? If not, try using "classpath:/frontal.properties" (adding a slash).
FLM_25
Mar 26th, 2008, 03:59 AM
Hi,
The properties file is found because when I deploy with another name, it's generate an IO exception : "Could not found file".
Marten Deinum
Mar 26th, 2008, 04:18 AM
I may hope that the contents of your properties file isn't the context you posted?
url.wsdl.bpm = http://localhost:8080/APP-BPM/services/ExecutionManager?wsdl
Which means the name of your property is 'url.wsdl.bpm ' instead of 'url.wsdl.bpm' (notice the space!).
Next to that I would set the 'ignoreUnresolvablePlaceholders' to false so that if a placeholder cannot be replaced you will get an exception, now it simply ignores the fact that it cannot locate the property.
FLM_25
Mar 26th, 2008, 05:02 AM
With 'url.wsdl.bpm = ' or 'url.wsdl.bpm=' or 'url.wsdl.bpm= ' the problem is the same. It doesn't replace the key.
Here my logs :
2008-03-26 09:55:39,217 {INFO } {commons.logging.impl.Log4JLogger} Loading properties file from class path resource [frontal.properties]
2008-03-26 09:55:39,217 {INFO } {commons.logging.impl.Log4JLogger} Loading properties file from class path resource [frontal.properties]
2008-03-26 09:55:39,220 {DEBUG} {commons.logging.impl.Log4JLogger} Resolved placeholder 'url.wsdl.bpm'
2008-03-26 09:55:39,220 {DEBUG} {commons.logging.impl.Log4JLogger} Resolved placeholder 'url.wsdl.bpm'
I haven't any exceptions
Marten Deinum
Mar 26th, 2008, 05:28 AM
Are your beans loaded in the same ApplicationContext?
FLM_25
Mar 26th, 2008, 07:57 AM
Yes i have just one application context
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.