title: How to define @Value as optional
body: <p>I have the following in a Spring bean:</p>
  
  <pre><code>@Value("${myValue}")
  private String value;
  </code></pre>
  
  <p>The value is correctly injected. However, the variable needs to be optional, it is passed in as a command line parameter (which is then added to the Spring context using a <strong>SimpleCommandLinePropertySource</strong>), and this argument will not always exist.</p>
  
  <p>I have tried both the following in order to provide a default value:</p>
  
  <pre><code>@Value("${myValue:}")
  @Value("${myValue:DEFAULT}")
  </code></pre>
  
  <p>but in each case, the default argument after the colon is injected even when there is an actual value - this appears override what Spring should inject.</p>
  
  <p>What is the correct way to specify that <strong>@Value</strong> is not required?</p>
  
  <p>Thanks</p>