> Markdown version of [CDI](https://vaadin.com/docs/next/flow/integrations/cdi). Section index: [llms.txt](https://vaadin.com/docs/next/flow/llms.txt)

# Using CDI with Vaadin

Contexts and dependency injection (CDI) is a framework for injecting dependency objects in different contexts. It’s part of the Java EE platform, but its purpose is similar to autowiring in Spring.

The [Vaadin CDI](https://github.com/vaadin/cdi) add-on allows you to use Vaadin with [CDI](https://tools.jboss.org/features/cdi.html).

## <a id="tutorial"></a>Tutorial

A tutorial application which showcases the basic usage of a Vaadin CDI application is available at <https://github.com/vaadin/flow-cdi-tutorial>. You can use this application example to test the different concepts and features presented in the documentation.

## <a id="starting-a-project"></a>Starting a Project

To start a new project with CDI and Vaadin, you can get a project base for Vaadin and CDI from [`vaadin.com/hello-world-starters`](https://vaadin.com/hello-world-starters). This is a project template with the necessary configuration and dependencies included for starting to build your own application. This starter is also available for cloning from [GitHub](https://github.com/vaadin/cdi).

## <a id="add-dependencies"></a>Add Dependencies

The `vaadin-cdi` add-on should be packaged in your application and deployed to an application server that’s compliant with Jakarta EE 10 or later.

Import the Vaadin Bill of Materials (BOM), and add the `vaadin-cdi` add-on and the Jakarta EE API with the `provided` scope to your `pom.xml`:

`pom.xml`

```xml
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
         <groupId>com.vaadin</groupId>
         <artifactId>vaadin-cdi</artifactId>
    </dependency>
    <dependency>
        <groupId>jakarta.platform</groupId>
        <artifactId>jakarta.jakartaee-web-api</artifactId>
        <version>11.0.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
```

## <a id="vaadin-version-compatibility"></a>Vaadin Version Compatibility

The version for `vaadin-cdi` is managed by `vaadin-bom`.

You need the Jakarta CDI API version 4.0.1 and a provided implementation. In practice, because other Jakarta EE features are used together with CDI, the simplest way to ensure compatibility is to use a Jakarta EE 10 or later container.

## <a id="configure-vaadin-cdi-add-on"></a>Configure Vaadin CDI Add-On

No specific CDI configuration options exist.

An instance of the CDI-enabled Vaadin servlet, `com.vaadin.cdi.CdiVaadinServlet`, is deployed automatically, provided you don’t setup a Vaadin servlet in your `web.xml` or use the `@WebServlet` annotation. You can also customize `CdiVaadinServlet` to suit your setup.

> **Note:** See [Configuration Properties](https://vaadin.com/docs/next/flow/configuration/properties.md) for more information about Vaadin servlet configuration.

## <a id="limitations"></a>Limitations

The Vaadin CDI add-on doesn’t support Hilla, because Hilla requires the use of Spring.

## <a id="browserless-testing"></a>Browserless Testing

Use [Weld-backed browserless tests](https://vaadin.com/docs/next/building-apps/testing/browserless/setup-cdi.md) to exercise CDI-managed Flow views without deploying the application. The [testing reference](https://vaadin.com/docs/next/flow/testing/browserless/cdi.md) describes lifecycle ordering and the boundary between the CDI and Vaadin contexts.
