Is it possible to @Lazy
init a Spring @Value
?
e.g.
@Lazy
@Value("${someConfig}")
private String someConfig;
The scenario I'm specifically referring to, is a variable which is set via JNDI, and an embedded Tomcat container, which has some of it's JNDI variables initialised during Spring Boot loading... 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.
The above code gives the following error:
java.lang.IllegalArgumentException: Cannot subclass final class java.lang.String
I imagine you could possibly achieve lazy-loaded variables by using a @ConfigurationProperties
bean?
A follow up question: Can/Would a @Value
-initialised variable be reinitialised (without an app restart), if the underlying variable source is changed (e.g. JNDI on the server)? i.e. re-retrieved
(I'm in the process of trying these last two scenarios)