Announcement Announcement Module
Collapse
No announcement yet.
SOLVED -Unable to register two PropertyPlaceholderConfigurer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    This might just be me, but the placeholder you are using appears to be misspelled- aplication.driver instead of applicaton.driver?

    Rob

    Comment


    • #3
      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

      Comment


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

        Comment


        • #5
          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

          Comment


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

            Comment

            Working...
            X