Announcement Announcement Module
Collapse
No announcement yet.
Multiple property files within multiple modules/projects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple property files within multiple modules/projects

    Let's say I have the following modules/projects:

    -) myAppDAO
    -) myAppJabber
    -) myApp

    Each project has its own spring context. Since I need to load db / jabber connection properties, I have a PropertyPlaceholderConfigurer set up for both of them (each in their own context file):

    Code:
    <bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	<property name="ignoreResourceNotFound" value="true" />
    	<property name="locations">
    		<list>
    			<value>classpath:/db.default.properties</value>
    			<value>classpath:/db.properties</value>
    		</list>
    	</property>
    </bean>
    Code:
    <bean id="jabberProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	<property name="ignoreResourceNotFound" value="true" />
    	<property name="locations">
    		<list>
    			<value>classpath:/jabber.default.properties</value>
    			<value>classpath:/jabber.properties</value>
    		</list>
    	</property>
    </bean>
    The problem comes in when I'm using both modules in my main application where I load the context files from every module - creating one big application context. Now it seems like only one PropertyPlaceholderConfigurer gets used and I get exceptions when I try to inject a property from the other one into a bean: "Could not resolve placeholder 'db.host'"

    When I add the jabber.properties in the PropertyPlaceHolderConfigurer of the dao module (or vice versa), everything works just fine. It also works if I remove the PropertyPlaceHolderConfigurer from both modules and just add one big one in the main application. Both ways suck imo.

    What would be the correct way to load a dedicated property file for each project/module and still use them alltogether in one context?

  • #2
    You can have multiple <contextroperty-placeholder /> elements instead of explicitly declaring multiple PropertiesPlaceholderConfigurer beans.

    Comment


    • #3
      Mhmm.. I just tried it, but I got the same result.

      In the context file of the DAO module I specified:

      Code:
      <context:property-placeholder location="classpath:/db.default.properties, classpath:/db.properties" ignore-resource-not-found="true"/>
      Same with the context file in the jabber module:

      Code:
      <context:property-placeholder location="classpath:/jabber.default.properties, classpath:/jabber.properties" ignore-resource-not-found="true"/>
      But once I load both context files into my main application context, only one propertyplaceholder works. In my case it's the one from the DAO module since I load its context file first. Loading of the jabber module context file then fails with with the usual "Could not resolve placeholder 'jabber.host'"

      Comment


      • #4
        Turns out that I was missing ignore-resource-not-found="true" .. now it works like expected. It even works with the previous notation where a specified sperate beans for the PPHC.

        Comment


        • #5
          I was having the same problem and found this thread.

          I think you meant to say in your last comment that you were missing the ignoreUnresolvablePlaceholders=true property as opposed to the ignoreResourceNotFound property. That's what got it working for me.

          Comment

          Working...
          X