Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer problem with properties files. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment


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

        Comment


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

          Comment

          Working...
          X