Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For new Jakarta Faces code, use CDI @Named with a CDI scope that fits the bean’s lifecycle. Faces @ManagedBean is deprecated, and the documented replacement direction is CDI. The annotations may both make a bean addressable from a Facelets page, but they belong to different management systems and are not interchangeable.

What each annotation does

The key distinction is the package and the system that manages the bean:

  • jakarta.inject.Named gives a CDI bean a name for expression-language (EL) access. CDI handles bean discovery, injection, and contextual lifecycle behavior.
  • jakarta.faces.bean.ManagedBean registers a class as a Faces managed bean. This annotation-based Faces mechanism is deprecated; the Faces API directs developers toward CDI.

In older Java EE applications, the corresponding namespaces are javax.inject.Named and javax.faces.bean.ManagedBean. Jakarta EE 9 and later use the jakarta.* namespace. Use imports that match the platform and dependencies your application actually targets.

There is also a different annotation named ManagedBean: jakarta.annotation.ManagedBean. It is not the Faces annotation. The Jakarta EE Platform 10 API describes it as providing basic resource injection, lifecycle callbacks, and interceptor services, and deprecates it in favor of CDI. When code shows only the short annotation name, inspect its import before deciding what it means.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Comparison at a glance

Concern CDI @Named Faces @ManagedBean
Jakarta package jakarta.inject.Named jakarta.faces.bean.ManagedBean
Role Names a CDI bean so EL can address it Registers a Faces managed bean
Scope Must be paired with an appropriate CDI scope; @Named is not a scope Historically used Faces scope annotations or configuration
Default name First character of the class name lowercased Derived from the unqualified class name when the name is absent or empty
Explicit name May be set, for example, with @Named("MyPrinter") May be supplied with the annotation’s name attribute
Constructor expectation CDI rules apply; the Jakarta EE tutorial describes a no-argument constructor or an appropriate @Inject constructor The Faces API requires a public zero-argument constructor
Current direction Use for new CDI-managed beans that need an EL name Deprecated; documented replacement guidance points to CDI

For example, the Jakarta EE tutorial demonstrates a CDI bean with @Named and @SessionScoped, which a Facelets page can address through the bean name. Choose the scope separately: a session-scoped bean, for instance, lives across requests in a user’s session, while other CDI scopes suit different lifetimes.

How to choose and migrate

For new beans

Use CDI @Named when a Facelets or other EL expression needs to refer to a CDI bean. Add a CDI scope annotation that reflects how long the state should live. Do not assume that adding @Named alone gives the bean a particular lifecycle.

For an existing Faces managed bean

Do not treat migration as a token-for-token annotation swap. Check the bean’s scope, injection points, EL name, serialization needs, and startup behavior, then map those requirements to CDI. The target runtime and its dependencies matter, so confirm that the deployed platform supports the CDI APIs and namespace you plan to import.

  1. Identify the fully qualified old annotation and scope imports. In Jakarta applications, distinguish jakarta.faces.bean.ManagedBean from jakarta.annotation.ManagedBean; in older Java EE code, check the corresponding javax.* imports.
  2. Choose CDI scopes that preserve the bean’s intended lifecycle, and review how its injection points will be managed.
  3. Preserve or deliberately change the EL name. Review Facelets references and search for duplicate names: the Faces API warns that duplicate managed-bean names cause a FacesException and prevent the application from being placed in service.
  4. If the old bean used @ManagedBean(eager=true) for eager initialization of an application-scoped bean, review the CDI event-based replacement pattern. The API points to observing CDI’s Initialized event for ApplicationScoped.
  5. Check the target runtime’s official documentation and test the migrated application on that runtime; imports and API availability depend on the platform generation and dependency set.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Sources and platform versions

The distinction and deprecation guidance are documented in the Jakarta Faces 3.0 API documentation. CDI naming and the Facelets example appear in the Jakarta EE tutorial’s Faces configuration material and its CDI basics chapter. For the similarly named annotation in another package, see the Jakarta EE Platform 10 API documentation. The older namespace is documented in the Java EE 7 Faces API and the Java EE 7 Inject API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.