> Markdown version of [Vaadin Legacy CDI Application with MPR & Flow](https://vaadin.com/docs/next/tools/mpr/introduction/3-cdi). Section index: [llms.txt](https://vaadin.com/docs/next/tools/llms.txt)

# Vaadin Legacy CDI Application with MPR & Flow

This step is needed if your Vaadin 7 or 8 application uses CDI. If it doesn’t, go back to the [framework selection](https://vaadin.com/docs/next/tools/mpr/introduction/3-legacy-uis.md).

## <a id="updating-to-correct-cdi-version"></a>Updating to Correct CDI version

You need to remove any version from `com.vaadin:vaadin-cdi` since the compatible version for it is managed by the `vaadin-bom`. Instead, the `pom.xml` file should look like this:

```xml
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-cdi</artifactId>
</dependency>
```

<!-- vale Vaadin.Abbr = NO -->

## <a id="handling-cdiui-annotation"></a>Handling CDIUI Annotation

<!-- vale Vaadin.Abbr = YES -->

Instead of using `@CDIUI`, as shown below, use `@Route` and `@CdiComponent`.

```java
@CDIUI
@Theme("valo")
public class TodoUI extends UI {
    @Override
    protected void init(VaadinRequest vaadinRequest) {
        setContent(new HorizontalLayout());
    }
}
```

Below is an example of how a replacement for what’s shown above might look:

```java
@Route("")
@CdiComponent
public class TodoUI extends Div implements HasLegacyComponents {
    @PostConstruct
    private void buildLayouts() {
        setSizeFull();
        add(new HorizontalLayout());
    }
}
```

Annotations in the UI, such as `@Theme` and `@Title`, are dealt with later in the tutorial. Most of them have similar counterparts in either Flow or MPR.

## <a id="handling-cdi-views"></a>Handling CDI Views

Any `@CDIView` should be updated to a Flow Route by wrapping them as a `MprRouteAdapter<? extends View>` or re-writing them to be a Flow Component. See [Upgrading Views to Flow Routes](https://vaadin.com/docs/next/tools/mpr/introduction/3-navigator.md#no-navigator) for more information on this.

## <a id="handling-viewscopes"></a>Handling ViewScopes

All ViewScopes should be changed to RouteScopes. For example, `@ViewScoped` should be changed to `@RouteScoped`, and `@NormalViewScoped` changed to `@NormalRouteScoped`.

In some projects, CDI has ignored the archive and has not instantiated objects as expected. This is fixed by adding a `beans.xml` file — an empty file with this name is enough — to `src/main/webapp/WEB_INF`. Additionally, all Vaadin components that should be managed by the CDI container, should be annotated with `@CdiComponent`, or set `bean-discovery-mode=all` in `beans.xml`. However, this is not a recommended method.

The next step is [Configuring UI Parameters](https://vaadin.com/docs/next/tools/mpr/introduction/4-ui-parameters.md).

`5092446E-699F-40C4-A994-D5804AF8C7B3`
