Chapter 2. Managed Beans

Managed Beans is defined as part of JSR 316, and the complete specification can be downloaded from http://jcp.org/aboutJava/communityprocess/final/jsr316/index.html.

A managed bean is a POJO that is treated as a managed component by a Java EE container. It provides a common foundation for different kinds of components that exist in the Java EE platform. In addition, the specification also defines a small set of basic services such as resource injection, lifecycle callbacks, and interceptors on these beans.

Different component specifications can add other characteristics to this managed bean. The specification even defines well-known extension points to modify some aspects. For example, Contexts and Dependency Injection (CDI) relaxes the requirement to have a POJO with a no-args constructor, and allows constructors with more complex signatures. CDI also adds support for lifecycle scopes and events. Similarly, Enterprise JavaBeans is a managed bean and adds support for transactions and other services. This allows the developer to start light and create a more powerful component such as an EJB or CDI bean if and when the need arises.

Typically, a managed bean is not used by itself in a Java EE application. However, the concepts defined are very relevant to Java EE and allow you to build other component specifications on it.

Define and Use a Managed Bean

A managed bean is a POJO with a no-args constructor with the class-level annotation javax.annotation.ManagedBean ...

Get Java EE 6 Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.