title: Is it possible to @Lazy init a Spring @Value?
body: <p><strong>Is it possible to <code>@Lazy</code> init a Spring <code>@Value</code>?</strong></p>
  
  <p>e.g.</p>
  
  <pre><code>@Lazy
  @Value("${someConfig}")
  private String someConfig;
  </code></pre>
  
  <p>The scenario I'm specifically referring to, is a variable which is set via JNDI, and <a href="https://stackoverflow.com/questions/28131577/spring-boot-using-embedded-tomcat-with-jndi">an embedded Tomcat container, which has some of it's JNDI variables initialised during Spring Boot loading</a>... other scenarios I could think of where you'd want JIT variable population: It's "expensive" to retrieve a variable and you don't want to impact startup time, the variable isn't available at application startup, etc.</p>
  
  <p>The above code gives the following error:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Cannot subclass final class
    java.lang.String</p>
  </blockquote>
  
  <p>I imagine you could possibly achieve lazy-loaded variables by using a <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties" rel="nofollow noreferrer"><code>@ConfigurationProperties</code> bean</a>?</p>
  
  <p>A follow up question: <strong>Can/Would a <code>@Value</code>-initialised variable be reinitialised (without an app restart), if the underlying variable source is changed (e.g. JNDI on the server)?</strong> i.e. re-retrieved</p>
  
  <p>(I'm in the process of trying these last two scenarios)</p>