You can simply do it with the following method:
public static <T> T getBeanInstance(final Class<T> type, final Class<? extends Annotation> scope, final BeanManager beanManager) { final Context context = beanManager.getContext(scope); final Set<<Bean<?>> beans = beanManager.getBeans(type); final Bean<T> bean = (Bean<T>) beanManager.resolve(beans); final CreationalContext<T> creationalContext = beanManager.createCreationalContext(bean); return context.get(bean, creationalContext); }
PLEASE you can explique me when i would use the BeanInstance instead of the reference?
ReplyDeleteA case use of it?
Another question:
how i can get a @ApplicationScoped BEan eager like the manaagedBEan of JSF but with OWB ?
i would that the @ApplicationScoped Bean OWB it is created at web application startup.
Like with the managedBean of JSF2 @ApplicationScoped(eager=true)
But without the Ejb Singleton with annotation @Startup .
I would get the @ApplicationScoped at startup web application only with OWB .
i have read that it is possiblecreate a extension but not understand how to make it.
mauro
mauro
UseCase: If you need to pass a bean to another thread.
ReplyDeleteEager Extension: http://ovaraksin.blogspot.de/2013/02/eager-cdi-beans.html
ReplyDeletethank u for sharing this postthank u for sharing this postcustom web application development
Thankyou for sharingcustomized purchase software management
ReplyDeleteWe really enjoy the blog which gives real examples, so that anyone can know. Great job! Great job! Keep it up.
ReplyDeleteEnterprise Application Development Company