Search code examples
springcdilazy-initialization

How to make a CDI bean lazily initialized?


I am using Weld implementation of CDI 1.0 and I cannot find way how to make bean lazy like in Spring (using @Lazy or lazy-init in XML). Is there a way how to tell CDI's Injector not to initialize bean on startup?


Solution

  • No, this isn't possible in CDI. The closest thing you could get would be to create a new InjectionPoint (using an Extension) implementation that gives a proxy and the proxy would initialize everything on the first method invocation.