Results 1 to 5 of 5

Thread: Referencing files outside webroot

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default Referencing files outside webroot

    Hi.

    I need to reference a jdbc.properties outside of /webapps/<webroot>, and am currently trying to do this using a PropertyPlaceholderConfigurer. However, the amount of success is very limited.

    Code:
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<!--property name="location"><value>/WEB-INF/jdbc.properties</value></property-->
    		<property name="location"><value>/../../app_local_config/avik2/jdbc.properties</value></property>
    	</bean>
    Two questions:
    1) Does PropertyPlaceholderConfigurer support relative paths?
    2) Is there a more clever way of accessing files/properties/etc outside of /webapps and(or) /approot?

    Thanks in advance!
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Relative paths in a web app are not very deterministic across different servers. Some of the server have the bin directory set as the working dir, some don't.

    One solution: you can of course set the location to an absolute URL.

    Another soluttion is to create a server-specific property editor (but I don't like this too much). Most servers have some proprietary ways of getting to the config or data directory (JBoss for example has the ServiceLocator I think).
    Alef Arendsen
    SpringSource
    http://www.springsource.com

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

    Default

    The PropertyPlaceHolderConfigurer treats the locations it is given as Resources. The way things are set up is that the Resource it gets will actually use the application context as the resource loader. So in the case of deploying in an XmlWebApplicationContext, the locations will be relative to the servlet context base. But you can still override with the standard spring Resource prefixes. So you can do
    classpath:some/class/path/xxx.properties
    or
    file:/some/path/xxx.properties
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  4. #4
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default

    Thanks a lot!
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

  5. #5
    Join Date
    Aug 2004
    Location
    Columbus, OH, USA
    Posts
    133

    Default

    Quote Originally Posted by Colin Sampaleanu
    But you can still override with the standard spring Resource prefixes. So you can do
    classpath:some/class/path/xxx.properties
    or
    file:/some/path/xxx.properties
    That really is helpful, especially when using the same applicationContext.xml for both the web context listener and for container-less JUnit tests. I hit this problem when I added a PropertyPlaceholderConfigurer and found the locations to be resolved differently depending on how I loaded the application context.

    Now this works in both cases:

    Code:
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="locations">
    			<list>
    				<value>classpath&#58;/myapp/resources/email/email.properties</value>
    				<value>classpath&#58;/myapp/resources/rdb/ppHostRdb/ppHostRdb.properties</value>
    			</list>
    		</property>
    	</bean>
    Scott

Similar Threads

  1. Referencing beans in different config files
    By halcyon in forum Container
    Replies: 11
    Last Post: Oct 29th, 2007, 01:57 AM
  2. Replies: 16
    Last Post: Jan 12th, 2007, 01:18 PM
  3. Replies: 0
    Last Post: Aug 9th, 2005, 11:49 AM
  4. Replies: 7
    Last Post: Jul 26th, 2005, 02:48 PM
  5. Unexpected behaviour with multiple config files
    By rgitzel in forum Container
    Replies: 7
    Last Post: Mar 8th, 2005, 07:11 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
  •