Announcement Announcement Module
Collapse
No announcement yet.
Referencing files outside webroot Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    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).

    Comment


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

      Comment


      • #4
        Thanks a lot!

        Comment


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

          Comment

          Working...
          X