Java EE 6 @Inject懒惰? [英] Java EE 6 @Inject lazy?

查看:248
本文介绍了Java EE 6 @Inject懒惰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对我们正在开发的应用程序进行一些重构和审核。在这样做时我发现注入了更多的豆子,我认为以懒惰的方式装载它们会更适合它们的目的。我正在使用Java EE 6,并且倾向于使用比EJB注入更多的CDI。

I am doing some refactoring and reviewing of the application that we are currently developing. While doing this I found that more beans are injected and I think making they loading in an lazy manner would be better suited for their purpose. I am using Java EE 6 and tend to use more CDI than EJB injection.

所以问题是是否有可能懒得注入豆类,如果是这样,你怎么能这样做?

So the question is whether it is possible to inject the beans lazily and if so, how can you do it?

推荐答案

如何使用

@Inject
private Instance<?> lazyProvider;

这允许获取?的实例实际需要时通过

That allows Getting instance of "?" when actually needed via

lazyProvider.get();

这篇关于Java EE 6 @Inject懒惰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆