liveBook · Manning

CDI bean

As explained in Quarkus in Action

A CDI bean is a Java object managed by a CDI container according to contextual dependency-injection rules.

A CDI bean is a Java object managed by the CDI container according to contextual dependency-injection rules. In Quarkus, application beans appear alongside built-in beans created by the framework. REST endpoints are CDI beans even when their classes have no CDI annotation; a REST endpoint uses @Singleton as its default scope. section 3.3.1

Use Quarkus Dev UI and ArC to inspect how beans participate in an application:

  • Open the ArC extension and select Beans to list application and built-in CDI beans. section 3.3.1
  • Inspect each bean’s scope and type; a class-based bean such as org.acme.GreetingResource is shown with its CDI scope. section 3.3.1
  • Follow the Bean Dependency Graph to visualize dependencies, or open an application bean directly in the detected IDE. section 3.3.1
  • During testing, replace CDI beans that are unsuitable for direct execution with mocks, including remote-service dependencies. section 5.0
Figure 3.4 List of the application’s CDI beans in the Dev UI, including beans added through the application code and auxiliary beans generated by Quarkus
figure

Use the Dev UI bean table to distinguish application beans from Quarkus-generated auxiliary beans and inspect their scopes and types. section 3.3.1

Figure 3.5 The Bean Dependency Graph of the GreetingResource class
figure

Use the dependency graph to trace the relationships around the GreetingResource bean. section 3.3.1

How Quarkus in Action covers it

How deep it goes
Explains bean listings, scopes, types, IDE links, and dependency graphs, but does not detail CDI lifecycle or resolution internals.
Examples
Uses GreetingResource, the ArC Beans table, the Bean Dependency Graph, and mocked CDI beans for remote services.
What it assumes
Assumes familiarity with Java application classes and introduces Quarkus’s CDI bean inspection and testing facilities.
What you can do after
Diagnose/debug with it by listing beans, checking scopes and types, tracing dependencies, and substituting test doubles.
How it connects
Connects CDI beans with CDI containers, dependency injection, REST endpoints, scopes, testing mocks, and dependency graphs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.