Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceHolderConfigurration Classpath Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyPlaceHolderConfigurration Classpath Problem

    Hi,
    I am using PropertyPlaceHolderConfiguration to read the property outside the war file. To do so I used the code
    <bean class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <!-- property name="ignoreResourceNotFound" value="true"/> -->

    <!-- property name="location" value="classpath:${config}\test.properties" /> -->
    <property name="location" value="file:${config}\test.properties" />
    </bean>

    When I give classpath:${config}\test.properties at the startup time it give me error java.io.FileNotFoundException: class path resource [C:/Amit/property/test.properties] cannot be opened because it does not exist.

    But if I use file: then it works fine.
    I wanted to know what wrong I am doing with classpath:.
    In the examples of PropertyPlaceHolderConfiguration everywhere they are writing value="classpath:xyz.properties" , in this case where in classpath it will search xyz.properties. I am using web application and using Tomcat or Weblogic, if I user this then where I need to put my xyz.properties file so that it can be read from the classpath.

    Many thanks in advance.

  • #2
    Well obviously ${config} is replaced with "C:\Amit\property" in your configuration. Classpath is the directory where your application's resources are stored (if you use Maven, that's src/main/resources or src/test/resources). So classpath resources should be relative to that directory, not relative to C: disk.

    Comment


    • #3
      But in my case my property file should be present outside the war directory structure. If I go with src then I need to make change my property file for each environemnt(Dev,QA, Stag,Prod). Hence if I give classpath:xyz.properties is there way without src(which is in application classpath) it can read the properties from outside. Like in case of Weblogic there would be conf or user_projects\domains\myDom if I put xyz.properties here, will it read from there.

      Comment


      • #4
        I know nothing about WebLogic, but it makes no difference. No matter where you deploy/run/test your application, classpath is the directory (or jar file) where your compiled .class files are stored. So resources in the classpath always go together with your application bytecode. If you say "classpath:xyz.properties", Spring will search for xyz.properties file in the classpath, wherever it is.

        But do I understand it right that you do not want to keep this file in the classpath for some reason?

        Comment

        Working...
        X