quarkusio/quarkus · error · DefinitionException
Different scopes defined for: ${target}; scopes: ${scopes}
Error message
Different scopes defined for: ${target}; scopes: ${scopes} What it means
When computing a bean's scope, Arc collects scope annotations from the class, stereotypes, and producer elements. If more than one distinct scope is found, the resolution is ambiguous and Arc throws DefinitionException listing the target and all conflicting scopes. CDI allows at most one scope per bean (plus @Dependent implicit).
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java:1080
boolean inherited = clazz.hasDeclaredAnnotation(DotNames.INHERITED);
if (clazz.hasDeclaredAnnotation(DotNames.SCOPE)) {
return new ScopeInfo(scopeAnnotationName, false, inherited);
} else if (clazz.hasDeclaredAnnotation(DotNames.NORMAL_SCOPE)) {
return new ScopeInfo(scopeAnnotationName, true, inherited);
}
}
}
return null;
}
static ScopeInfo getValidScope(Set<ScopeInfo> scopes, AnnotationTarget target) {
switch (scopes.size()) {
case 0:
return null;
case 1:
return scopes.iterator().next();
default:
throw new DefinitionException(
"Different scopes defined for: " + target + "; scopes: " + scopes.stream().map(ScopeInfo::getDotName)
.map(DotName::toString).collect(Collectors.joining(", ")));
}
}
record BeanDiscoveryResult(List<BeanInfo> beans, List<SkippedClass> skippedClasses) {
}
/**
* A class found during discovery but skipped for a specific reason.
*/
record SkippedClass(ClassInfo clazz, SkippedReason reason) {
}
enum SkippedReason {
EXCLUDED_TYPE,
VETOED,
NO_BEAN_DEF_ANNOTATION,View on GitHub (pinned to e1c734241f)
Solutions
- Remove one of the conflicting scope annotations so only a single scope remains
- Remove the scope from the stereotype (or from the bean class) so they agree
- If overriding is intended, ensure the direct scope annotation takes precedence per CDI rules (a stereotype scope can be overridden by an explicit scope on the bean — re-check that the stereotype is actually applied where you think)
- Split the stereotype into two if some users need a different scope
Example fix
// before
@ApplicationScoped @MyRequestScopedStereotype class Foo {}
// after
@MyRequestScopedStereotype class Foo {} // stereotype supplies the single scope Defensive patterns
Strategy: validation
Validate before calling
Set<DotName> scopes = new HashSet<>();
if (clazz declaredScope != null) scopes.add(declaredScope);
stereotypes.stream().map(BeanDeployment::stereotypeScope).filter(Objects::nonNull).forEach(scopes::add);
if (scopes.size() > 1) throw new IllegalStateException("Conflicting scopes: " + scopes); Try / catch
try { deployment.init(); }
catch (DefinitionException e) { log.error("Conflicting scopes on " + target + " — keep one scope only"); throw e; } Prevention
- Don't declare an explicit scope on beans that use scope-carrying stereotypes
- Ensure all stereotypes applied to a class share the same scope
- Audit stacked stereotypes for scope conflicts after refactors
When it happens
Trigger: A bean class annotated with, e.g., @ApplicationScoped and also carrying a stereotype that declares @RequestScoped; or a producer method whose scope conflicts with its declaring class's stereotype scope without explicit override.
Common situations: Applying a stereotype that carries a scope to a class that also declares its own scope; stacking multiple stereotypes each with different scopes; copy-paste annotations after refactoring.
Related errors
- Stereotype must not declare @Named with a non-empty value: $
- Components annotated with multiple conflicting scopes must d
- Qualifier annotation '${qualifierClass}' contains a member '
- A decorator must be @Dependent but ${decoratorClass} declare
- Interceptor declares scope other than @Dependent:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/bc8f2118a1ba13c9.
Report an issue: GitHub.