0

I have been tasked to deploy a ROOT.war app on Apache Tomcat. Here's what the ROOT.war file looks like on the inside:

ROOT.war file structure

The app I was told uses a Postgresql as its database. I already have sorted that one out.

I just want to know how to run this app on Apache Tomcat using this application.properties configuration file they have provided. Here's what it looks like:

application.properties config

Thank you very much and regards, Jeremy

jeremybcenteno
  • 119
  • 4
  • 15
  • 1
    Try placing the `application.properties` file inside `classes/resources` directory – R.G Mar 06 '20 at 17:36
  • Hello @R.G thank you very much for your help. But unfortunately, I still can't make it work. Tomcat at port 8080 still throws me a 404 not found error. – jeremybcenteno Mar 06 '20 at 17:51
  • how did you confirm the app was deployed correctly and the URL you are hitting is as expected ? localhost:8080/ROOT returns 404 is it ? – R.G Mar 06 '20 at 17:57
  • I am not entirely sure that the application has been deployed correctly. What I tried to do is check the *catalina.log* inside the Tomcat installation directory. And this line in the log caught my eye and what made me think that the location of the application.properties file is the problem. – jeremybcenteno Mar 06 '20 at 18:14
  • `2020-03-06 17:49:20.679 WARN 9710 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [asia.edusuite.sample.Application]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'property.location' in value "file:${property.location}/application.properties"` – jeremybcenteno Mar 06 '20 at 18:14
  • Yes, I have been checking the application on localhost:8080 and localhost:8080/ROOT – jeremybcenteno Mar 06 '20 at 18:15
  • Could you try providing an environment variable `property.location=resources` , place the `application.properties` within `classes/resources directory` . May be this [link](https://stackoverflow.com/a/23957805/4214241) will give you hints on how to do it – R.G Mar 06 '20 at 18:23
  • or may be this [link](https://stackoverflow.com/q/17019233/4214241) – R.G Mar 06 '20 at 18:26

1 Answers1

0

There are may ways to specify the location of the application.properties file. See Spring Boot Documentation for full list of how properties are loaded.

As described in section 2.3. Application Property Files:

SpringApplication loads properties from application.properties files in the following locations and adds them to the Spring Environment:

  • A /config subdirectory of the current directory

  • The current directory

  • A classpath /config package

  • The classpath root

It goes on to say:

If you do not like application.properties as the configuration file name, you can switch to another file name by specifying a spring.config.name environment property. You can also refer to an explicit location by using the spring.config.location environment property (which is a comma-separated list of directory locations or file paths).

Of the many options, I'd highlight:

  • Recommended: According to this answer, you can specify the location in the Tomcat context XML file, although that is not explicitly specified in the Spring documentation:

    <Context>
        <Parameter name="spring.config.location" value="file:/path/to/config/folder" />
    </Context>
    
  • Modify the .war file and place the file in the WEB-INF/classes/config or WEB-INF/classes folder.

  • If you can specify the working directory for the running Tomcat, place the file there or in a config sub-folder.

  • If you can specify a JVM option for the running Tomcat, add -Dspring.config.location=file:/path/to/config/folder, and place the file there.

Community
  • 1
  • 1
Andreas
  • 154,647
  • 11
  • 152
  • 247