Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a property file in the shared folder in tomcat 8 and using it in a Spring MVC web application

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.

folder

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?

like image 568
Geo Thomas Avatar asked Dec 24 '22 05:12

Geo Thomas


2 Answers

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.

like image 136
Joao Esperancinha Avatar answered Jan 05 '23 00:01

Joao Esperancinha


Check out this answear. Maybe it will help

Where to place and how to read configuration resource files in servlet based application?

like image 41
Mafick Avatar answered Jan 04 '23 23:01

Mafick