Results 1 to 5 of 5

Thread: Multiple property files within multiple modules/projects

  1. #1
    Join Date
    Nov 2008
    Location
    Vienna, Austria
    Posts
    9

    Default 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. #2

    Default

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

  3. #3
    Join Date
    Nov 2008
    Location
    Vienna, Austria
    Posts
    9

    Default

    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'"

  4. #4
    Join Date
    Nov 2008
    Location
    Vienna, Austria
    Posts
    9

    Default

    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.

  5. #5

    Default

    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.

Posting Permissions

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