I have a Java Spring MVC web application. I was using an application.properties file to set a few properties value. Now I am trying to get the properties independent of the war file. I have created a new folder shared/classes under tomcat as shown here.
In the catalina.properties
file I have added shared.loader=${catalina.base}/shared/classes
.
In my root-context.xml
file, I added
<context:property-placeholder location="file:${catalina.base}/shared/classes/application.properties"/>
But I am getting the following error:
ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: E:\projects\smartwcm\workspace-20163101-eclipse-wp\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\shared\classes\application.properties (The system cannot find the path specified)
How can I fix this issue?
This is probably one of the limitations of the Servers folder created by eclipe. Where it actually places the contents of this folder is in
.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf
I've tried this locally and eclipse doesn't seem to publish any folder I create. And eclipse is very specific in naming the folder Tomcat v8.0 Server at localhost-config
. This may also imply that property and configuration files are the only accepted system files. I can make everything work very well just by putting an application.properties
file at the same level as for example catalina.properties
. Then I publish with eclipse and then when I look at the temporary folder, the application file is there. Anyways there doesn't seem to be a specific reason to have your file in shared/classes
. After all, as far as I can tell, they are properties to be shared in the server, so I would say their rightfull place is in the config folder.
Check out this answear. Maybe it will help
Where to place and how to read configuration resource files in servlet based application?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With