Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PropertyPlaceholderConfigurer loading external property file

 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my applicationContext.xml, I am trying to load a property file from where I will get JDB URL's , LDAP Configuration, etc.. I added location to where appProperties.properties exists to the websphere classpath. I have configured through console.



But when my App is started, I am getting IO Exceptions.


Is there any setting where I could say look at the classpath to get the property file instead of looking for this file in the WEB-INF/classes
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er, WEB-INF/classes *is* on the classpath. Use a full classpath URI:

http://almaer.com/blog/spring-propertyplaceholderconfigurer-a-nice-clean-way-to-share
 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. I did not mention this earlier. Application that I am working on is Web application.

I don't want property file to be part of the web application. I have property file in local directory out of web application say "c:\myApp\properties"
I have added this folder to the classpath of myApp in websphere that way when myApp is loaded it can find the property file.

I have also tried placing this file in web-inf/classes and still it does not work. I got same exception.

I don't know why it is not finding property file when it is in WEB-INF/classes folder.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saritha ventrapragada wrote:Application that I am working on is Web application.

I kind of figured that out, what with the WEB-INF reference and all.
I don't want property file to be part of the web application.

Why not? That's going to make it pretty deployment-specific.
I have added this folder to the classpath of myApp in websphere that way when myApp is loaded it can find the property file.

Yuck.
I don't know why it is finding property file when it is in WEB-INF/classes folder.

Because it's on the classpath? Or did you say opposite things two sentences apart?
 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want my property file to be part of Web-application as it contains configuration's for LDAP and JDBC in the property file.
Configurations may change from env to env (IT, ST and PROD). Hence I don't want to bundle my property file as part of the application.

Initially I had my property file out side of web app and it was not found.
Later I tried having it as part of the application and still it was not found.

I don't want to hardcode location to the property file in ApplicationContext.xml as path will differ from env to env.

Please let me know why do you think approach that I took is wrong and can you please suggest correct approach for my problem.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saritha ventrapragada wrote:I don't want my property file to be part of Web-application as it contains configuration's for LDAP and JDBC in the property file.

Still not a great solution--why not just override the property placeholder configurator to do something like take a property file prepended with the server, or to look for property names with the environment in it, or... Otherwise use a "file:" prefix to specify an absolute path. But IMO using an absolute path is more brittle than the other options I mentioned.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic