title: Spring: How to inject a value to static field?
body: <p>With this class</p>
  
  <pre><code>@Component
  public class Sample {
  
      @Value("${my.name}")
      public static String name;
  
  
  }
  </code></pre>
  
  <p>If I try <code>Sample.name</code>, it is always 'null'. So I tried this.</p>
  
  <pre><code>public class Sample {
  
      public static String name;
  
      @PostConstruct
      public void init(){
          name = privateName;
      }
  
      @Value("${my.name}")
      private String privateName;
  
      public String getPrivateName() {
          return privateName;
      }
  
      public void setPrivateName(String privateName) {
          this.privateName = privateName;
      }  
  
  }
  </code></pre>
  
  <p>This code works. <code>Sample.name</code> is set properly. Is this good way or not? If not, is there something more good way? And how to do it?</p>