What is a CDI bean?

CDI does not introduce a new bean type called a CDI Bean with its own unique component model.

CDI provides a set of services that can be consumed by managed beans and EJBs that are defined by their existing component models.

So, CDI is just a Bean (EJB or Managed Bean) handling CDI lifecycle with scope for Context and other old feature DI .


CDI got introduced in Java EE 6 to provide some of the features available earlier to EJB only to all components managed by container. So CDI bean covers Servlets, SOAP web service, RESTful web service, entities, EJBs etc.

So you can use all these terms interchagebly :

  • CDI bean
  • bean
  • managed bean
  • EJB bean
  • container managed bean etc.

CDI bean is a bean managed by CDI container (Weld for example).

  • If it is @injected - it is bean

  • If it is may @injects something - it is bean too.


CDI beans are classes that CDI can instantiate, manage, and inject automatically to satisfy the dependencies of other objects. Almost any Java class can be managed and injected by CDI.

For example, PrintServlet got dependency on a Message instance and have it injected automatically by the CDI runtime.

PrintServlet.java

@WebServlet("/printservlet")
public class PrintServlet extends HttpServlet {
    @Inject private Message message;

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.getWriter().print(message.get());
    }
}

Message.java (This class is a CDI bean)

@RequestScoped
public class Message {
    @Override
    public String get() {
        return "Hello World!";
    }
}

Cheers!