title: How to integrate a Spring Boot profile with Maven profile?
body: <p>I am trying to integrate <code>Spring Boot</code> profile with <code>Maven</code> profile but for some reason always the <code>default</code> profile is getting picked up.</p>
  
  <p><strong>mvn clean test -Dspring.profiles.active=prod (WORKING)</strong></p>
  
  <p><strong>Logs:</strong></p>
  
  <pre><code>2019-07-01 17:02:15.013  INFO 21872 --- [           main] com.example.BrowserTest                  : The following profiles are active: prod
  2019-07-01 17:02:15.405  INFO 21872 --- [           main] com.example.BrowserTest                  : Started BrowserTest in 0.743 seconds (JVM running for 1.757)
  ************************************************************************
  ************************************************************************
  Site: https://www.yahoo.com
  ************************************************************************
  ************************************************************************
  [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.509 s - in com.example.BrowserTest
  </code></pre>
  
  <p><strong>mvn clean test -Prod (DOES NOT WORK, ALWAYS PICKS THE default PROFILE)</strong></p>
  
  <p><strong>Logs:</strong></p>
  
  <pre><code>2019-07-01 17:03:20.136  INFO 17532 --- [           main] com.example.BrowserTest                  : The following profiles are active: @activatedProperties@
  2019-07-01 17:03:20.535  INFO 17532 --- [           main] com.example.BrowserTest                  : Started BrowserTest in 0.727 seconds (JVM running for 1.706)
  ************************************************************************
  ************************************************************************
  Site: http://www.default.com
  ************************************************************************
  ************************************************************************
  [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.456 s - in com.example.BrowserTest
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <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;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.6.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;profiles-junit-demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;profiles-junit-demo&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&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;/dependencies&gt;
  
      &lt;build&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/resources&lt;/directory&gt;
                  &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;/resource&gt;
          &lt;/resources&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;configuration&gt;
                      &lt;profiles&gt;
                          &lt;profile&gt;dev&lt;/profile&gt;
                          &lt;profile&gt;prod&lt;/profile&gt;
                      &lt;/profiles&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;dev&lt;/id&gt;
              &lt;properties&gt;
                  &lt;activatedProperties&gt;dev&lt;/activatedProperties&gt;
              &lt;/properties&gt;
              &lt;activation&gt;
                  &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
              &lt;/activation&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;prod&lt;/id&gt;
              &lt;properties&gt;
                  &lt;activatedProperties&gt;prod&lt;/activatedProperties&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>src/test/resources/application.properties</strong></p>
  
  <pre><code>spring.profiles.active=@activatedProperties@
  site=http://www.default.com
  </code></pre>
  
  <p><strong>src/test/resources/application-dev.properties</strong></p>
  
  <pre><code>site=https://www.google.com
  </code></pre>
  
  <p><strong>src/test/resources/application-prod.properties</strong></p>
  
  <pre><code>site=https://www.yahoo.com
  </code></pre>
  
  <p><strong>BrowserTest.java</strong></p>
  
  <pre><code>public class BrowserTest extends ProfilesJunitDemoApplicationTests {
  
      @Value("${site}")
      private String site;
  
      //mvn clean test
      //mvn clean test -Dspring.profiles.active=dev
      //mvn clean test -Dspring.profiles.active=prod
      //mvn clean test -Pprod - NOT WORKING :(
      @Test
      public void homePage() {
          System.out.println("************************************************************************");
          System.out.println("************************************************************************");
          System.out.println("Site: " + site);
          System.out.println("************************************************************************");
          System.out.println("************************************************************************");
          assertNotNull(site);
      }
  
  }
  </code></pre>