1

I want to put my application properties file in Tomcat's conf directory therefore I wrote

<context:property-placeholder location="${catalina.base}/conf/app.properties"/>

I get FileNotFoundException: Could not open ServletContext resource. The app.properties file is there. Problem is an additional slash at the beggining of the path the Spring is looking for the file at. It looks like /D:/...../conf/app.properties

Solution: Writing ......location="file:${catalin..... worked.

user435421
  • 859
  • 2
  • 13
  • 31

1 Answers1

4

You need to specify as file since you are trying to read from external file as: <context:property-placeholder location="file:${catalina.base}/conf/app.properties"/>

It should be similar to this: How to read values from properties file?

Yogen Rai
  • 2,961
  • 3
  • 25
  • 37
  • What do you mean by "need to make sure that catalina.base is set correctly so that context would be able to read the file". I am sure cataline base shows to the right directory because the path in the exception stack trace looks like `/D:/XX/MY_PROJ_NAME/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf/app.properties`. When I copy this path from Eclipse's console and remove the first slash the file gets opened in Notepad when I type it in the Windows file explorer. Same happens when I prepend file:// to the `/D:/XX/XX/tmp0/conf/app.properties` and try to access it via file explorer. – user435421 Feb 05 '18 at 18:23
  • By "same happens" I mean the file gets opened by Notepad but not by application. – user435421 Feb 05 '18 at 18:24
  • Hmmm... obviously, the second one looks correct! and I am doing the same which is reading properties for and populating the placeholders!! – Yogen Rai Feb 05 '18 at 18:29
  • @user435421 sounds cool!! Would you please accept the answer and upvote – Yogen Rai Feb 06 '18 at 16:42
  • If you will add to your answer that `file:` might be the solution besides `file://` then I would do that. For the readers who might miss my updated solution part in the question... – user435421 Feb 07 '18 at 09:43
  • @user435421 thank you for pointing this out.. :) I didn’t notice that.. you are awesome :) – Yogen Rai Feb 07 '18 at 13:34