Skip to content

Fix Quarkus CDI Injection Not Working

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Fix Quarkus CDI Injection Not Working. We cover key concepts, practical examples, and best practices.

The Problem

Quarkus CDI injection fails with UnsatisfiedResolutionException. Beans are not found.

Quick Fix

Add @ApplicationScoped

Wrong:

@Inject ProductService service;
// ProductService not scoped

Output:

UnsatisfiedResolutionException

Right:

@ApplicationScoped
public class ProductService { }

Output:

Bean registered

Use @Produces for factories

Wrong:

// No @Produces
public class Config {
    public DataSource ds() { }
}

Output:

Bean not created

Right:

@ApplicationScoped
public class Config {
    @Produces
    public DataSource dataSource() { }
}

Output:

Bean created

Use @Dependent for narrow scopes

Wrong:

@Singleton
public class HttpClient { } // Held longer than needed

Output:

Memory leak

Right:

@Dependent
public class HttpClient { } // Created per injection point

Output:

Proper scope

Prevention

  • Annotate beans with CDI scopes (@ApplicationScoped, @RequestScoped, @Dependent)
  • Use @Produces for factory methods
  • Choose proper scope based on lifecycle

Common Mistakes with cdi injection

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world QUARKUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does @Singleton cause issues in Quarkus?

Use @ApplicationScoped instead of @Singleton for Quarkus beans. @ApplicationScoped supports proxies.

This quick fix is part of the DodaTech Spring & JVM ecosystem series. Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro