title: Property resolving for multiple Spring profiles (yaml configuration)
body: <p>Is there a defined order when multiple profiles are used for a property resolution.</p>
  <p>I have yaml configuration file:</p>
  <pre class="lang-yaml prettyprint-override"><code>name: none
  ---
  spring:
    profiles: prod
  name: prodName
  ---
  spring:
    profiles: dev
  name: devName
  </code></pre>
  <p>When application runs with no (default) profile, <code>none</code> is printed. For dev/prod profiles devName/prodName is printed (so far so good).</p>
  <p>When I tried to define profile as <code>dev,prod</code> <code>prodName</code> is printed,when I specify <code>prod,dev</code> <code>devName</code> is printed.</p>
  <p><em>Is this something I can rely on?</em> I mean is it specified in Spring? I didn't find it <a href="https://docs.spring.io/spring-boot/docs/1.2.2.RELEASE/reference/html/boot-features-external-config.html" rel="nofollow noreferrer">here</a>.</p>
  <h1>full version (for replication)</h1>
  <h2>application.yml</h2>
  <pre><code>name: none
  ---
  spring:
    profiles: dev
  name: devName
  ---
  spring:
    profiles: prod
  name: prodName
  </code></pre>
  <h2>Configuration.java</h2>
  <pre><code>import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.stereotype.Component;
  
  import java.util.ArrayList;
  import java.util.List;
  
  @Component
  @ConfigurationProperties
  public class Configuration {
  
      String name;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  <h2>SpringBootConsoleApplication.java</h2>
  <pre><code>import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.CommandLineRunner;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  import java.util.List;
  
  @SpringBootApplication
  public class SpringBootConsoleApplication implements CommandLineRunner {
  
      private static Logger LOG = LoggerFactory.getLogger(SpringBootConsoleApplication.class);
  
      @Autowired
      Configuration conf;
  
      public static void main(String[] args) {
          SpringApplication.run(SpringBootConsoleApplication.class, args);
      }
  
      @Override
      public void run(String... args) {
          LOG.info(&quot;name: {}&quot;, conf.name);
      }
  
  }
  </code></pre>
  <p><strong>edit:</strong></p>
  <p><a href="https://github.com/Betlista/SpringPropertyResolutionMultipleProfiles" rel="nofollow noreferrer">GitHub repository</a></p>
  <p>sample output:</p>
  <pre class="lang-none prettyprint-override"><code>c:\betlista\SpringPropertyResolutionMultipleProfiles&gt;java -jar target\spring-boot-console-app-1.0.jar
  ...: name: none, label: labelValue
  
  c:\betlista\SpringPropertyResolutionMultipleProfiles&gt;java -jar -Dspring.profiles.active=dev target\spring-boot-console-app-1.0.jar
  
  ...: name: devName, label: labelValue
  
  c:\betlista\SpringPropertyResolutionMultipleProfiles&gt;java -jar -Dspring.profiles.active=dev,prod target\spring-boot-console-app-1.0.jar
  
  ...: name: prodName, label: labelValue
  
  c:\betlista\SpringPropertyResolutionMultipleProfiles&gt;java -jar -Dspring.profiles.active=prod,dev target\spring-boot-console-app-1.0.jar
  
  ...: name: devName, label: labelValue
  </code></pre>
  <p><strong>edit 2:</strong></p>
  <h1>Topics</h1>
  <p>There was a question which I'd refer to as topics - <a href="https://stackoverflow.com/questions/56118147/multiple-properties-file-for-a-single-spring-profile">Multiple properties file for a single spring profile</a></p>
  <p>While one can use <code>@PropertySource</code> with property files, it cannot be used with YAML files. The only solution I know at the moment is to used e.g. <code>-Dspring.config.additional-location=classpath:topic1.yml</code></p>
  <p><strong>edit 3:</strong></p>
  <p>The <a href="https://stackoverflow.com/questions/60333056/property-resolving-for-multiple-spring-profiles-yaml-configuration">&quot;duplicate&quot; question</a> has same questions as I have here, but without an answer. That question was about beans, not really a properties. Accepted answer says &quot;<code>spring.profiles.active system property</code> doesn't matter.&quot;, which I shown as incorrect (within context of properties). Please vote for reopen if you agree.</p>