Java EE 6 @Inject lazy? [duplicate]

我的未来我决定 提交于 2019-12-06 02:21:57

问题


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?


回答1:


What about using

@Inject
private Instance<?> lazyProvider;

?

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

lazyProvider.get();


来源:https://stackoverflow.com/questions/15920758/java-ee-6-inject-lazy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!