如何使CDI bean延迟初始化? [英] How to make a CDI bean lazily initialized?
本文介绍了如何使CDI bean延迟初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用CDI 1.0的Weld实现,但找不到像Spring那样使bean变得懒惰的方式(在XML中使用@Lazy
或lazy-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.
这篇关于如何使CDI bean延迟初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文