no

How to create an instance bean in JavaEE using its class

JavaEE6 has really revolutionize the development using CDI (from seam) but there are times when we need to create an instance of a class not...

JavaEE6 has really revolutionize the development using CDI (from seam) but there are times when we need to create an instance of a class not by injection but by other means such as Component.getInstance from seam.

In seam we have something like
MyClass myClass = (MyClass) Component.getInstance("MyClass");

In JavaEE6, we do that by:
Bean bean = (Bean) beanManager.getBeans(MyClass.class).iterator().next();
CreationalContext ctx = beanManager.createCreationalContext(bean);
return (MyClass) beanManager.getReference(bean, MyClass.class, ctx);


I use this type of approach normally with FacesConverters.

Related

javaee 7483223706328466407

Post a Comment Default Comments

Outsourcing

Are you looking for freelancers in the Philippines? Get in touch.

Donations

If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.

item