Results 1 to 6 of 6

Thread: SOLVED -Unable to register two PropertyPlaceholderConfigurer

  1. #1

    Default SOLVED -Unable to register two PropertyPlaceholderConfigurer

    Hi,

    I'm trying to use two PropertyPlaceholderConfigurers but I'm getting a BeanDefinitionStoreException each time I try to read a value from the second one.

    I've the following web.xml entry:

    Code:
    	<context-param>
    		<param-name> contextConfigLocation </param-name>
    		<param-value> /WEB-INF/menuContext.xml, /WEB-INF/appContext.xml </param-value>
    	</context-param>
    In menuContext.xml:

    Code:
    	<bean id="menuPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location">
    		    <value>classpath&#58;menu.properties</value>
    		</property>
    	</bean>
    in appContext.xml:

    Code:
    	<bean id="projectPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location">
    		    <value>classpath&#58;project.properties</value>
    		</property>
    	</bean>
    Using this configuration I can't read any property from project.properties.

    If I switch the order in web.xml:

    Code:
    	<context-param>
    		<param-name> contextConfigLocation </param-name>
    		<param-value> /WEB-INF/appContext.xml, /WEB-INF/menuContext.xml </param-value>
    	</context-param>
    I can't read any data from menu.properties.

    The trace I get in the first case is:

    Code:
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG BeanWrapperImpl &#58; 997 - Converting String to &#91;interface org.springframework.core.io.Resource&#93; using property editor &#91;org.springframework.core.io.ResourceEditor@9ac0f5&#93;
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG BeanWrapperImpl &#58; 829 - About to invoke write method &#91;public void org.springframework.core.io.support.PropertiesLoaderSupport.setLocation&#40;org.springframework.core.io.Resource&#41;&#93; on object of class &#91;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&#93;
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG BeanWrapperImpl &#58; 834 - Invoked write method &#91;public void org.springframework.core.io.support.PropertiesLoaderSupport.setLocation&#40;org.springframework.core.io.Resource&#41;&#93; with value of type &#91;org.springframework.core.io.Resource&#93;
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG DefaultListableBeanFactory &#58; 344 - Invoking setBeanName on BeanNameAware bean 'projectPropertyConfigurer'
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG DefaultListableBeanFactory &#58; 351 - Invoking setBeanFactory on BeanFactoryAware bean 'projectPropertyConfigurer'
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG DefaultListableBeanFactory &#58; 235 - Invoking BeanPostProcessors before initialization of bean 'projectPropertyConfigurer'
    &#91;SPRING&#93; 17&#58;25&#58;28 DEBUG DefaultListableBeanFactory &#58; 254 - Invoking BeanPostProcessors after initialization of bean 'projectPropertyConfigurer'
    &#91;SPRING&#93; 17&#58;25&#58;28  INFO PropertyPlaceholderConfigurer &#58; 167 - Loading properties file from class path resource &#91;menu.properties&#93;
    &#91;SPRING&#93; 17&#58;25&#58;28 ERROR ContextLoader &#58; 177 - Context initialization failed
    org.springframework.beans.factory.BeanDefinitionStoreException&#58; Error registering bean with name 'appDataSource' defined in ServletContext resource &#91;/WEB-INF/appContext.xml&#93;&#58; Could not resolve placeholder 'aplication.driver'
    Here appDataSource is the bean that tries to use ${aplication.driver}

    I've been trying several things with the names and the declarations without success. I looked for something like this in Jira without success (so this means I'm doing something wrong).

    Any comment here would be really welcome.

    Regards,

    - Juan

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    This might just be me, but the placeholder you are using appears to be misspelled- aplication.driver instead of applicaton.driver?

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3

    Default

    It was a typo in the post (I translated the names to english to make them crearer). Unfortunately it has the same name in the .properties file and in the xml descriptor in the source code.

    Regards,

    - Juan

  4. #4

    Default

    Can anyone confirm that this kind of configuration is working for him? Or should I raise a bug for it?

  5. #5
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    If you want two different PropertyPlaceholderConfigurers to resolve the same placeholder syntax - by default: ${...} - then you need to set each PropertyPlaceholderConfigurer's "ignoreUnresolvablePlaceholders" flag to "true". Else, each placeholder configurer will complain if it finds a placeholder that it cannot resolve (as it doesn't know about the other configurer and assumes that an unresolvable placeholder constitutes a fatal error).

    Alternatively, you could also use different placeholder syntax: PropertyPlaceholderConfigurer's "placeholderPrefix" and "placeholderSuffix" settings allow for specifying specific prefix/suffix syntax for each configurer. For example, one configurer could keep resolving ${...} while another one could resolve #{...}

    Juergen

  6. #6

    Default

    Juergen, thank you for your crystal clear post. Not only solved the problem but explained perfectly how PropertyPlaceholderConfigurer works.

Similar Threads

  1. Replies: 2
    Last Post: Oct 31st, 2005, 03:03 PM
  2. Beandoc crashing (on its samples!)
    By aaime in forum Container
    Replies: 17
    Last Post: Oct 7th, 2005, 07:21 AM
  3. Replies: 3
    Last Post: Oct 6th, 2005, 12:45 AM
  4. PerformanceMonitorInterceptor
    By tnist in forum AOP
    Replies: 3
    Last Post: Aug 24th, 2005, 01:39 PM
  5. Replies: 5
    Last Post: Jul 13th, 2005, 07:02 PM

Posting Permissions

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