title: Spring @Value annotation not using defaults when property is not present
body: <p>I am trying to use @Value annotation in the parameters of a constructor as follows:</p>
  
  <pre><code>@Autowired
  public StringEncryptor(
      @Value("${encryptor.password:\"\"}") String password,
      @Value("${encryptor.algorithm:\"PBEWithMD5AndTripleDES\"}") String algorithm,
      @Value("${encryptor.poolSize:10}") Integer poolSize, 
      @Value("${encryptor.salt:\"\"}") String salt) {
  ...
  }
  </code></pre>
  
  <p>When the properties file is present on the classpath, the properties are loaded perfectly and the test executes fine. However when I remove the properties file from the classpath, I would have expected that the default values would have been used, for example poolSize would be set to 10 or algorithm to PBEWithMD5AndTripleDES however this is not the case. </p>
  
  <p>Running the code through a debugger (which would only work after changing <code>@Value("${encryptor.poolSize:10}") Integer poolSize</code> to <code>@Value("${encryptor.poolSize:10}") String poolSize</code> as it was causing NumberFormatExceptions) I find that the defaults are not being set and the parameters are in the form of: </p>
  
  <p><code>poolSize = ${encryptor.poolSize:10}</code> or</p>
  
  <pre><code>algorithm = ${encryptor.algorithm:"PBEWithMD5AndTripleDES"}
  </code></pre>
  
  <p>rather than the expected</p>
  
  <p><code>poolSize = 10</code> or</p>
  
  <pre><code>algorithm = "PBEWithMD5AndTripleDES"
  </code></pre>
  
  <p>Based on <a href="https://jira.springsource.org/browse/SPR-4785" rel="noreferrer">SPR-4785</a> the notation such as ${my.property:myDefaultValue} should work. Yet it's not happening for me!</p>
  
  <p>Thank you</p>