如何使CDI bean延迟初始化?

如何使CDI bean延迟初始化?

问题描述:

我正在使用CDI 1.0的Weld实现,但找不到像Spring那样使bean变得懒惰的方式(在XML中使用@Lazylazy-init).有没有办法告诉CDI的Injector在启动时不要初始化bean?

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?

否,这在CDI中是不可能的.最可能得到的是创建一个新的InjectionPoint(使用扩展)实现,该实现提供一个代理,并且代理将在第一次方法调用时初始化所有内容.

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.