Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - Where to put properties files when deploying to Tomcat?

I've been using Spring Boot for a few weeks already, and I'm used to work with the application.properties file. I'm able to use it for simple deployment and use with java jar or mvn spring-boot:run.

Now I'm trying to deploy my application to a Tomcat 8.0.15 application server. I've been reading of documentation, but I can't deploy the war file because Tomcat can't find this famous application.properties file. My point is, if I want to put this file out of the war, where in my Tomcat installation should I put it for it to be automatically read?

like image 690
mrik974 Avatar asked Dec 19 '22 08:12

mrik974


2 Answers

If you don't want to change it later, just put it in the root of your classpath, e.g. if it's Maven project then inside

<project-folder>/src/main/java/

If you want to change it later without rebuilding WAR then in Tomcat properties file

catalina.properties 

there is

shared.loader=

that makes properties files listed after equals sign accessible to deployed applications. Better use absolute paths.

BTW, I would opt to use annotation-based configuration nowadays, but then again, it doesn't have the comfort of changing without rebuilding WAR.

like image 172
Kristjan Veskimäe Avatar answered Dec 29 '22 00:12

Kristjan Veskimäe


Spring loads the properties from

   1) A /config subdir of the current directory.
   2) The current directory
   3) A classpath /config package
   4) The classpath root 

See the docs(23.2 Application property files): http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files

This should work the same way for war(The classpath root one looks the best for me) .

like image 33
Evgeni Dimitrov Avatar answered Dec 29 '22 01:12

Evgeni Dimitrov