-
Apr 16th, 2011, 02:15 AM
#1
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.
-
Apr 18th, 2011, 08:57 AM
#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.
-
Apr 19th, 2011, 08:08 AM
#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.
-
Apr 19th, 2011, 09:39 AM
#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?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules