Results 1 to 5 of 5

Thread: PropertyPlaceholderConfigurer problem with properties files.

  1. #1
    Join Date
    Nov 2004
    Posts
    22

    Default PropertyPlaceholderConfigurer problem with properties files.

    Hi folks,
    Hope someone can help me out here, I have a applicationContext.xml that references a jdbc.properties file like this:

    Code:
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location"><value>/WEB-INF/jdbc.properties</value></property>
    	</bean>
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName"><value>$&#123;jdbc.driverClassName&#125;</value></property>
    		<property name="url"><value>$&#123;jdbc.url&#125;</value></property>
    		<property name="username"><value>$&#123;jdbc.username&#125;</value></property>
    		<property name="password"><value>$&#123;jdbc.password&#125;</value></property>
    	</bean>
    And this works fine when I use the XmlWebApplicationContext loading from the servlet, so when tomcat comes up it picks everything up as it should....

    However when I try to instantiate a ClassPathXmlApplicationContext and give it applicationContext.xml in it's constructor it's throwing a java.io.FileNotFoundException and stating that it can't open WEB-INF/classes/jdbc.properties

    Anyone any ideas? I feel a bit stuck...

    Thanks in advance,

    Marty

  2. #2
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    The location precised in the location property of the PropertyPlaceholderConfigurer is resolved using the notion of resource in the applicationContext. In a web aware one, the resource is searched from the root of the web app while a classpath aware one will not search this but in the classpath.
    So, you may use different configuration files depending on the environment you use (I imagine it is unit test and "production").

    HTH

    Olivier

  3. #3
    Join Date
    Nov 2004
    Posts
    22

    Default

    okay... so what you're saying is that in the web aware one the search is done from the context root i.e. /<appname>/ but in the Classpath one it just has to be on the classpath?

    Right.. but is the /WEB-INF/classes directory not automatically on the classpath when running in tomcat? So if I specify just jdbc.properties instead of /WEB-INF/classes/jdbc.properties it should work?

  4. #4
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    So if I specify just jdbc.properties instead of /WEB-INF/classes/jdbc.properties it should work?
    That's right, the classpath aware application context will look in the classpath, hence this directory (and also the root of the jars in /WEB-INF/lib and the jars of the "app server").

    Olivier

  5. #5
    Join Date
    Nov 2004
    Posts
    22

    Default

    cheers! shall give it a go first thing tomorrow! thanks lots!

Similar Threads

  1. FlowExecutionStorage in a DB
    By cacho in forum Web Flow
    Replies: 7
    Last Post: Oct 19th, 2009, 03:36 PM
  2. Problem in reading Property files.
    By Barani_mdu in forum Container
    Replies: 1
    Last Post: Aug 27th, 2007, 06:22 PM
  3. mappingDirectoryLocations problem with jar files
    By corwitt in forum Container
    Replies: 4
    Last Post: Oct 13th, 2005, 09:57 PM
  4. Replies: 3
    Last Post: Jun 19th, 2005, 04:53 PM
  5. Runtime edit of properties files
    By ht562 in forum Container
    Replies: 1
    Last Post: Jan 14th, 2005, 06:18 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
  •