IntelliJ IDEA 2020.2 Help

CDI

The Context and Dependency Injection (CDI) support in IntelliJ IDEA is based on the Java EE: Context and Dependency Injection plugin. This plugin is bundled with the IDE and enabled by default.

You can enable CDI support when creating a project or module. You can as well add CDI support for an existing module.

CDI in a module is represented by the corresponding CDI library in the module dependencies. You can download all the necessary library files right from within the IDE. You can also change the CDI version being used if and when needed.

Make sure that the CDI plugin is enabled

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Plugins | Installed.

  2. Locate the Java EE: Contexts and Dependency Injection plugin in the list, and make sure that the checkbox next to it is selected.

CDI plugin is enabled in the list of plugins

Enable CDI support when creating a project or module

  1. To create a new project, click Create New Project on the Welcome screen or select File | New | Project.

    To create a new module, open the necessary project and select File | New | Module.

  2. In the wizard that opens, select Java Enterprise on the left.

  3. From the Project SDK list, select the JDK that you want to use in your project.

    If the JDK is installed on your computer, but not defined in the IDE, select Add JDK and specify the path to the JDK home directory.

    If you don't have the necessary JDK on your computer, select Download JDK.

  4. Select the Java EE version to be supported, and specify the application server you want to use.

  5. From the Additional Libraries and Frameworks list, select the CDI: Context and Dependency Injection checkbox.

  6. Configure the library. You can use an existing library, create and use a new one, download the library files, or postpone setting up the library until a later time.

    Click Next.

    Creating new project with CDI support
  7. On the next page of the wizard, specify the name and location for the new project or module. Click Finish.

Adding CDI support for an existing module

  1. In the Project tool window, right-click the necessary module, and select Add Framework Support.

    To open the tool window, from the main menu, select View | Tool Windows | Project.

  2. From the list on the left, select the CDI: Context and Dependency Injection checkbox.

  3. Configure the library. You can use an existing library, create and use a new one, download the library files, or postpone setting up the library until a later time.

  4. Apply the changes and close the dialog.

Adding CDI support

As a result, the CDI library you have specified is added to the list of module dependencies.

Change the CDI version

  1. Click the Project Structure icon on the toolbar (or press Ctrl+Alt+Shift+S) to open the Project Structure dialog.

  2. Select Modules on the left and open the Dependencies tab.

  3. Select the necessary CDI library and click the Edit icon.

  4. In the Configure Project Library dialog, click Change Version.

  5. Open the Version list, and select a new library version. Apply the changes and close the dialog.

    Changing the CDI version

Last modified: 03 September 2020