title: how to configure 'dynamic key' in properties file loaded using @PropertySource in Spring
body: <p>Using Spring 4 <code>@Configuration</code> annotation, this is how I configure a properties file and refer in my application:</p>
  
  <p><strong>src/main/resources/errors.properties</strong></p>
  
  <pre><code>name.empty.error=name is empty
  department.empty.error=department is empty
  </code></pre>
  
  <p>Java code configuration and usage:</p>
  
  <pre><code>@Configuration
  @PropertySource("classpath:errors.properties")
  public class Sample {
      @Autowired
      private Environment env;
  
      public void usage() {
          String errorText = env.getProperty("name.empty.error");
      }
  </code></pre>
  
  <p>I'd like to specify 'key' of my errors.properties in the following manner:</p>
  
  <pre><code>{0}.empty.error={0} is empty
  </code></pre>
  
  <p>so that the <code>usage()</code> method would call something like</p>
  
  <pre><code>String errorText1 = env.getProperty("{}.empty.error", "name");
  String errorText2 = env.getProperty("{}.empty.error", "department");
  </code></pre>
  
  <p>How to do this? I remember something like this existed in Struts error message handling.</p>