Editing and validating your contexts and dependency injection projects

You can use the contexts and dependency injection deployment descriptor editor to edit and validate your beans.xml file.

Before you begin

Create a Java™ EE-faceted project (that is, a utility, EJB, web, connector, or application client project) in your workspace. For information about creating one of these projects, see: Creating and configuring Java EE projects using wizards.

About this task

In CDI 1.0, the beans.xml file is required in the packaging and deployment of a CDI-enabled project. The presence of the beans.xml file indicates to the container that the deployed module is a bean archive. The deployment descriptor is generated when you install the CDI facet. See Creating applications that use Contexts and Dependency Injection (CDI). Initially, the beans.xml file is empty, which means that any annotated interceptors, decorators, or alternatives that exist in your module are disabled. To enable these classes, you can configure them using the CDI deployment descriptor editor.

Starting in CDI 1.2, the beans.xml file is optional in the packaging and deployment of a CDI-enabled project. This file is not created when you add the CDI 1.2 facet. You can generate this file by right-clicking on your project and selecting Java EE Tools > Generate CDI Beans Deployment Descriptor Stub from the menu.

Procedure

  1. Open the context and dependency injection deployment descriptor editor Version 1.2 or higher. Double-click your beans.xml file.
  2. Click Add to add alternatives, decorators, and interceptors to your beans.xml file.

    Starting in CDI 1.2, you can also click Add to specify scan, which you can use to set exclusion filters. Exclusion filters prevent classes from being discovered as beans.

  3. In the CDI 1.2 editor or above, use the following bean-discovery-mode values to specify how to scan your bean archive: all,annotated, or none.

    The CDI deployment descriptor editor issues validation errors under the following conditions:

    • If you have alternatives classes, decorators classes, or interceptors classes that are empty.
    • If you have alternatives classes, decorators classes, or interceptors classes that are non-existent.
    • If you have alternatives classes, decorators classes, or interceptors classes that are duplicates.
    • If you have classes that do not have the appropriate @Alternative, @Interceptor, or @Decorator annotations.