quarkusio/quarkus · error · DefinitionException
Declaring class of a managed bean is generic, its scope must
Error message
Declaring class of a managed bean is generic, its scope must be @Dependent: ${beanClass} What it means
A managed bean whose declaring class is generic (declares type parameters) can only be instantiated with properly resolvable type arguments under @Dependent scope. Any other scope requires proxying, which cannot work with unresolved type variables, so ArC throws a DefinitionException.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java:1401
// 2. Stereotype scope
// 3. Bean defining annotation default scope
ScopeInfo scope;
if (scopes.isEmpty()) {
// Inheritance of type-level metadata: "A scope type explicitly declared by X and inherited by Y from X takes precedence over default scopes of stereotypes declared or inherited by Y."
scope = inheritScope(beanClass, beanDeployment);
if (scope == null) {
scope = initStereotypeScope(stereotypes, beanClass, beanDeployment);
if (scope == null) {
scope = initBeanDefiningAnnotationScope(beanDefiningAnnotationScopes, beanClass);
}
}
} else {
scope = scopes.get(0);
}
if (scope != null // `null` is just like `@Dependent`
&& !BuiltinScope.DEPENDENT.is(scope)
&& !beanClass.typeParameters().isEmpty()) {
throw new DefinitionException(
"Declaring class of a managed bean is generic, its scope must be @Dependent: " + beanClass);
}
if (!isAlternative) {
isAlternative = initStereotypeAlternative(stereotypes, beanDeployment);
}
if (name == null) {
name = initStereotypeName(stereotypes, beanClass, beanDeployment);
}
if (isAlternative) {
priority = initAlternativePriority(beanClass, priority, stereotypes, beanDeployment);
if (priority == null) {
// after all attempts, priority is still null, bean will be ignored
LOGGER.debugf(
"Ignoring bean defined via %s - declared as an @Alternative but not selected by @Priority or quarkus.arc.selected-alternatives",
beanClass.name());
return null;
}View on GitHub (pinned to e1c734241f)
Solutions
- Make the bean class @Dependent (or remove the scope annotation)
- Remove the type parameters by making the class concrete with specific types
- Introduce a non-generic producer or a concrete subclass per type instantiation
Example fix
// before
@ApplicationScoped
class Repo<T> { }
// after
@Dependent
class Repo<T> { } Defensive patterns
Strategy: validation
Validate before calling
// before annotating a generic class with a normal scope
if (!clazz.typeParameters().isEmpty()
&& scope != null && !BuiltinScope.DEPENDENT.is(scope)) {
// fix: make the class @Dependent or remove type params
} Try / catch
try {
quarkusBuild.start();
} catch (DefinitionException e) {
if (e.getMessage().contains("generic, its scope must be @Dependent")) {
logger.errorf("Make generic bean class @Dependent: %s", e.getMessage());
}
throw e;
} Prevention
- Keep generic bean classes @Dependent
- Prefer producers or concrete subclasses for normal-scoped beans
- Check for type parameters before adding @ApplicationScoped/@RequestScoped
When it happens
Trigger: Beans (public managed-bean creation) computes the bean's scope; scope is non-null and not @Dependent while beanClass.typeParameters() is non-empty.
Common situations: Adding @ApplicationScoped to a generic class like Repository<T>; upgrading Quarkus/ArC where this CDI rule became enforced; copy-pasting scope annotations onto generic base classes.
Related errors
- InterceptionProxy parameter must be a parameterized type: ${
- Producer field type is a parameterized type with a type vari
- @BindingsSource may only define a class type, got ${kind}: $
- A synthetic bean ${bean} was defined with invalid scope anno
- Type of injected Bean<T> does not match the type of the bean
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/56837512e55426ee.
Report an issue: GitHub.