title: WAR file deployed on Tomcat not reading application.properties File
body: <p>I've created a Demo REST API using Spring Boot Framework in Java. I wanted to deploy this API on Tomcat 8 as a WAR file. The API is already configured to compile down as a WAR file using Spring Initializr. But, when the API is deployed, its not reading <code>application.properties</code> file from the project.</p>
  
  <ul>
  <li>I've already tried using <code>@PropertySource</code> and <code>@PropertySources</code> annotations.</li>
  <li>I've also tried including <code>&lt;resources&gt;</code> tag in <code>&lt;build&gt;</code> tag in pom.xml file.</li>
  <li>I've also tried adding <code>.properties("classpath:application.properties")</code> to <code>ServletInitializer</code></li>
  </ul>
  
  <p>Nothing worked</p>
  
  <p><br></p>
  
  <h1>Update</h1>
  
  <p>I've used context-path as an example in this post. In my actual application, I have some properties stored in application.properties and the application is not reading them.</p>
  
  <p><br></p>
  
  <p><strong>Here's my code files:</strong></p>
  
  <ul>
  <li>application.properties</li>
  </ul>
  
  <pre><code>server.servlet.context-path=/api
  </code></pre>
  
  <ul>
  <li>Application.java</li>
  </ul>
  
  <pre><code>@SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <ul>
  <li>ServletInitializer.java</li>
  </ul>
  
  <pre><code>public class ServletInitializer extends SpringBootServletInitializer {
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  }
  </code></pre>
  
  <ul>
  <li>User.java</li>
  </ul>
  
  <pre><code>@RestController
  @RequestMapping("/user")
  public class User {
  
      @GetMapping("")
      public String getUser() {
          return "User is here...";
      }
  }
  </code></pre>
  
  <p>Hitting <code>localhost:8080/demo/api/user</code> URL should give our desired output, but its rather giving a 404 result. Whereas, hitting <code>localhost:8080/demo/user</code> is giving the desired output.
  This means that the applicaiton is not reading application.properties file because the default route of the api was set to <code>/api</code> in that file.</p>