Results 1 to 10 of 10

Thread: Use of the PropertyPlaceholderConfigurer within a WebContext

  1. #1
    Join Date
    Aug 2004
    Location
    Germany
    Posts
    2

    Default Use of the PropertyPlaceholderConfigurer within a WebContext

    Hi,

    i tried to use the PropertyPlaceholderConfigurer on a WebApplicationContext, but the replacement failed.

    I used the following code:
    Code:
     
          PropertyPlaceholderConfigurer lConfigurer = null;
          ApplicationContext lApplicationContext = null;
          ConfigurableListableBeanFactory beanFactory = null;
          Properties lProperties = null;
    
          ...
    
             lApplicationContext = WebApplicationContextUtils.getWebApplicationContext(
                   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

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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/...lderconfigurer

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Germany
    Posts
    2

    Default

    Thanks for the hint, now it works.

    Regards,

    Andreas Werner

  4. #4
    Join Date
    Mar 2008
    Posts
    4

    Default

    Hi,

    I have the same problem (In Spring 2.0.4), but your link is brokken.
    I use a webApplication like this :
    Code:
    	private IFrontalService frontalService = null;
    	protected WebApplicationContext wac = null;
    	
    	/* (non-Javadoc)
    	 * @see org.apache.struts.action.Action#setServlet(org.apache.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 :

    Code:
    	<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		  <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
    Code:
    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
    Last edited by FLM_25; Mar 26th, 2008 at 02:55 AM.

  5. #5
    Join Date
    Apr 2006
    Location
    South Carolina
    Posts
    122

    Default

    Is the properties file being found? If not, try using "classpath:/frontal.properties" (adding a slash).

  6. #6
    Join Date
    Mar 2008
    Posts
    4

    Default

    Hi,

    The properties file is found because when I deploy with another name, it's generate an IO exception : "Could not found file".

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I may hope that the contents of your properties file isn't the context you posted?

    Code:
    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8
    Join Date
    Mar 2008
    Posts
    4

    Default

    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 :
    Code:
    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

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Are your beans loaded in the same ApplicationContext?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10
    Join Date
    Mar 2008
    Posts
    4

    Default

    Yes i have just one application context

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •