Adam Bien's Weblog

How To Discover All Deployed Beans

import javax.enterprise.inject.Any;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.AnnotationLiteral;

BeanManager beanManager;

Set<Bean<?>> beans = beanManager.getBeans(Object.class,new AnnotationLiteral<Any>() {}));
        for (Bean<?> bean : beans) {

Enjoy discovering!

See you at Upcoming Java EE Workhops at MUC Airport!

NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming


A book about rethinking Java EE Patterns


Cool! BeanManager is new for me. Nice to know. Tnx.
BTW the "private" keyword can be left out ;-) (

Posted by Ivar on September 12, 2012 at 07:47 PM CEST #

I think there is something missing in the beans declaration. Am I wrong?

Posted by frank on September 12, 2012 at 11:17 PM CEST #

Nice one! Is there a recipe for Java EE 5, too?

Posted by Danilo Piazzalunga on September 13, 2012 at 01:18 AM CEST #

Hi Ivar,

sorry for the bloat--I removed "private",



Posted by Adam Bien on September 13, 2012 at 04:12 AM CEST #


you are not wrong--I always forget to escape generics (lesser than, greater than characters) and they are going to be swallowed by the browser.

Not it is fixed!,


Posted by Adam Bien on September 13, 2012 at 04:13 AM CEST #

Adam, how can I get an instance of the bean.getBeanClass()?

I tried:

CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
beanManager.getReference(bean, bean.getBeanClass(), creationalContext);

It worked, Is it right?


Posted by Sandro on December 04, 2012 at 11:48 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments