title: Spring Boot Properties as Environment variables
body: <p>I have come across some behaviour which seems inconsistent in how spring boot handles environment variables in application properties files vs configuration property classes. I am unsure whether this is a bug in spring or an error in my understanding of what "ought" to happen.</p>
  
  <p>I have </p>
  
  <pre><code>@Data
  @ConfigurationProperties("foo")
  @Validated
  public class ClientProperties {
  
      @NotBlank
      private String apiKey;
  
      @NotBlank
      private String uri;
  
  }
  </code></pre>
  
  <p>In the <code>application.properties</code> file I have:</p>
  
  <pre><code>foo.baseUri=https://system.appspot.com
  foo.uri=${foo.baseUri}/Valuation?apikey=${foo.apiKey}&amp;bar={bar}
  </code></pre>
  
  <h3>Setting Just FOO_APIKEY</h3>
  
  <p>If I run my app with:</p>
  
  <pre><code>export FOO_APIKEY=DEF
  </code></pre>
  
  <p>Then I get </p>
  
  <pre><code>APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Binding to target class ClientProperties(apiKey=null, uri=https://system.appspot.com/Valuation?apikey=DEF&amp;bar={bar}) failed:
  
      Property: foo.apiKey
      Value: null
      Reason: may not be empty
  </code></pre>
  
  <p>Note that in the URI the api key is set as expected as well as the base URI</p>
  
  <h3>Setting Just FOO_API_KEY</h3>
  
  <p>Next, if instead, I try to set just this property (remove the old env var):</p>
  
  <pre><code>export FOO_API_KEY=ABC
  </code></pre>
  
  <p>Then my app starts, but the values are not as expected. My logs show:</p>
  
  <pre><code>API Key: ABC.
  URI Property: ${foo.baseUri}/Insurance?apikey=${foo.apiKey}&amp;bar={bar}.
  </code></pre>
  
  <p>Note that now the base uri also disappeared as well as the API key being missing.</p>
  
  <h3>Setting Both Properties FOO_API_KEY and FOO_APIKEY</h3>
  
  <p>When I set both environment variables the app starts but the <code>apiKey</code> property of <code>ClientProperties</code> holds the value of the <code>FOO_APIKEY</code> export, where as the <code>uri</code> property of <code>ClientProperties</code> holds the value of the <code>FOO_API_KEY</code> export.</p>
  
  <pre><code>API KEY IS: ABC.
  URI IS: https://system.appspot.com/Insurance?apikey=DEF&amp;bar={bar}.
  </code></pre>
  
  <h3>Notes</h3>
  
  <p>I actually don't need the value from <code>ClientProperties.apiKey</code>. It's only ever used in the app via the <code>ClientProperties.uri</code> which is already being resolved in <code>application.properties</code>. However, I specify the property so that I can have validation to ensure the value gets set. I could remove the value from my class and everything would be ok - expect then I lose my validation.</p>
  
  <p>Spring boot version is: <code>1.5.10.RELEASE</code></p>