I have a web application built with Spring. It connects to a database using JDBC and the JDBC properties (URL, username, password, and so on) are all currently hard-coded.
The web app is deployed as a WAR file and runs on Tomcat 8.5
I want to move these properties to a myapp.properties
file that is outside of the deployed WAR file, where a user can tweak those properties to point to their own database.
On application startup, if the web app cannot find the file, I still want the application to start up and display a friendly "Sorry I can't connect to the database because the properties file is missing" message (rather than just have the web app fail to run).
I thought about putting myapp.properties
in the Tomcat conf directory (ex: /bin/apache-tomcat-8.5.53/conf/myapp.properties) and always load it from there, but I don't know how to programmatically determine that location of the tomcat conf folder.
Any ideas on how I should approach this?