Use Vaadin with CDI

The vaadin-cdi add-on allows you to use Vaadin with CDI. You need to package the add-on in your application, and need to deploy it to a Java EE 7 (or newer) compliant application server. For vaadin-platform user, what you need to do is adding the vaadin-bom dependency to the dependencyManagement section in your pom.xml:

XML

  1. <dependencyManagement>
  2. <dependencies>
  3. <dependency>
  4. <groupId>com.vaadin</groupId>
  5. <artifactId>vaadin-bom</artifactId>
  6. <version>${vaadin.version}</version>
  7. <type>pom</type>
  8. <scope>import</scope>
  9. </dependency>
  10. </dependencies>
  11. </dependencyManagement>
  12. <dependencies>
  13. <dependency>
  14. <groupId>com.vaadin</groupId>
  15. <artifactId>vaadin-cdi</artifactId>
  16. <version>10.0.0</version>
  17. </dependency>
  18. <dependency>
  19. <groupId>javax</groupId>
  20. <artifactId>javaee-api</artifactId>
  21. <version>7.0</version>
  22. <scope>provided</scope>
  23. </dependency>

Compatibility

Version 10 of the add-on works with Vaadin version 10, and 11.

Minimum requirement is CDI 1.2 API, and a provided implementation. In practice other Java EE/Jakarta EE features are used together with CDI, so the most simple way is ensure you have a Java EE 7 container or newer.

Configuration

If you do not setup a Vaadin Servlet by web.xml, or by @WebServlet annotation, a CDI enabled Vaadin servlet com.vaadin.cdi.CdiVaadinServlet is deployed automatically.

Otherwise you can customize it just like the original Vaadin Servlet. No special CDI config options exist.

Please refer to Changing Flow behavior with runtime configuration for details about Vaadin Servlet configuration.