title: Spring application properties profile with war file
body: <p>I am trying to package my project in a <code>.war</code> for a tomcat server deployment. I need the ability to use my <code>application.properties</code> <strong>OR</strong> <code>application-dev.properties</code> <strong>OR</strong> <code>appliation-qa.properties</code> <strong>OR</strong> <code>application-prod.properties</code>. Running the project with the embeded servlet I am able to specify via the command line which one I want to use, but, the project always uses <code>application.properties</code> when I package it as a <code>.war</code>. </p>
  
  <p>I use the following commands to run my project locally:</p>
  
  <ol>
  <li><code>mvn spring-boot:run</code></li>
  <li><code>mvn spring-boot:run -Drun.arguments="--spring.profiles.active=dev"</code></li>
  </ol>
  
  <p>And this command to package my project though bamboo for deployment:</p>
  
  <ul>
  <li><code>mvn package -Dspring.profiles.active=qa</code></li>
  </ul>
  
  <p><br/></p>
  
  <blockquote>
    <p>Application.java</p>
  </blockquote>
  
  <pre><code>    package com.pandera.wilson;
  
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.boot.builder.SpringApplicationBuilder;
      import org.springframework.boot.context.web.SpringBootServletInitializer;
      import org.springframework.context.annotation.ComponentScan;
      import org.springframework.core.env.AbstractEnvironment;
      import org.springframework.scheduling.annotation.EnableAsync;
      import org.springframework.scheduling.annotation.EnableScheduling;
  
      import javax.servlet.ServletContext;
      import javax.servlet.ServletException;
  
      import org.apache.log4j.Logger;
  
      /**
       * @author Gaurav Kataria
       * @author Austin Nicholas
       * @category Application
       */
  
      @SpringBootApplication
      @ComponentScan(basePackages = { "com.pandera.wilson" })
      @EnableAsync
      public class Application extends SpringBootServletInitializer {
  
          static final Logger logger = Logger.getLogger(Application.class);
  
          public static void main(String[] args) throws Exception {
  
              logger.info("Entering Application");
              SpringApplication.run(Application.class, args);
          }
  
          @Override
          protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
              return application.sources(Application.class);
          }
  
      }
  </code></pre>
  
  <p><br/></p>
  
  <blockquote>
    <p>pom.xml</p>
  </blockquote>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
          &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;wilson&lt;/artifactId&gt;
          &lt;version&gt;3.0.1&lt;/version&gt;
  
          &lt;packaging&gt;war&lt;/packaging&gt;
  
          &lt;properties&gt;
              &lt;java.version&gt;1.8&lt;/java.version&gt;
              &lt;start-class&gt;com.pandera.wilson.Application&lt;/start-class&gt;
          &lt;/properties&gt;
  
          &lt;parent&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
              &lt;version&gt;1.3.6.RELEASE&lt;/version&gt;
          &lt;/parent&gt;
  
          &lt;build&gt;
              &lt;finalName&gt;wilson-services&lt;/finalName&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
  
          &lt;dependencies&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
                  &lt;exclusions&gt;
                      &lt;exclusion&gt;
                          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                          &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
                      &lt;/exclusion&gt;
                      &lt;exclusion&gt;
                          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
                      &lt;/exclusion&gt;
                  &lt;/exclusions&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
                  &lt;scope&gt;provided&lt;/scope&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-log4j&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
                  &lt;scope&gt;test&lt;/scope&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
                  &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
                  &lt;version&gt;4.5.2&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.security.oauth&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-security-oauth2&lt;/artifactId&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
                  &lt;artifactId&gt;sqljdbc4&lt;/artifactId&gt;
                  &lt;version&gt;4.0&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.json&lt;/groupId&gt;
                  &lt;artifactId&gt;json&lt;/artifactId&gt;
                  &lt;version&gt;20160212&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;commons-io&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                  &lt;groupId&gt;com.microsoft.azure&lt;/groupId&gt;
                  &lt;artifactId&gt;azure&lt;/artifactId&gt;
                  &lt;version&gt;1.0.0-beta2&lt;/version&gt;
              &lt;/dependency&gt;
  
          &lt;/dependencies&gt;
  
          &lt;repositories&gt;
              &lt;repository&gt;
                  &lt;id&gt;spring-releases&lt;/id&gt;
                  &lt;url&gt;https://repo.spring.io/libs-release&lt;/url&gt;
              &lt;/repository&gt;
          &lt;/repositories&gt;
  
      &lt;/project&gt;
  </code></pre>
  
  <p><br/>
  <strong>EDIT 1:30PM 7-21-16</strong></p>
  
  <p>I've added the following to my pom.xml and tried packaging with <code>mvn package -P PROD</code>, however, when I hit <code>/about</code> I still see that I'm using <code>appliation.properties</code> instead of <code>application-prod.properties</code>.</p>
  
  <pre><code>&lt;profiles&gt;
      &lt;profile&gt;
          &lt;id&gt;QA&lt;/id&gt;
          &lt;properties&gt;
              &lt;spring.profiles.active&gt;qa&lt;/spring.profiles.active&gt;
          &lt;/properties&gt;
      &lt;/profile&gt;
  
      &lt;profile&gt;
          &lt;id&gt;DEV&lt;/id&gt;
          &lt;properties&gt;
              &lt;spring.profiles.active&gt;dev&lt;/spring.profiles.active&gt;
          &lt;/properties&gt;
      &lt;/profile&gt;
  
      &lt;profile&gt;
          &lt;id&gt;PROD&lt;/id&gt;
          &lt;properties&gt;
              &lt;spring.profiles.active&gt;prod&lt;/spring.profiles.active&gt;
          &lt;/properties&gt;
      &lt;/profile&gt;
  &lt;/profiles&gt;
  </code></pre>