Announcement Announcement Module
No announcement yet.
PropertyPlaceholderConfigurer problem with properties files. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 file like this:

    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location"><value>/WEB-INF/</value></property>
    	<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>
    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 and stating that it can't open WEB-INF/classes/

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

    Thanks in advance,


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




    • #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 instead of /WEB-INF/classes/ it should work?


      • #4
        So if I specify just instead of /WEB-INF/classes/ 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").



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