Java EE 6 @Inject lazy?

I am refactoring and reviewing the application we are currently developing. By doing this, I found that more beans are being introduced, and I think that loading them in a lazy manner is better suited for their purposes. I use Java EE 6 and tend to use more CDI than EJB injection.

So, the question is, is it possible to lie lazily beans, and if so, how to do it?

+5
source share
1 answer

How about using

@Inject
private Instance<?> lazyProvider;

?

This allows you to get an instance of "?" when it is really necessary through

lazyProvider.get();
+13
source

All Articles