quarkusio/quarkus · error · DefinitionException
Injected field cannot be annotated with @Produces: ${field}
Error message
Injected field cannot be annotated with @Produces: ${field} What it means
A field annotated @Inject (an injected field, i.e. managed by the container) cannot also be annotated @Produces. Producer fields must not be injection targets; ArC throws this DefinitionException during field scanning of the bean class.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java:1305
"Observer method found but %s has no bean defining annotation - using @Dependent",
beanClass);
}
}
}
}
}
DotName superType = aClass.superName();
aClass = superType != null && !superType.equals(DotNames.OBJECT)
? getClassByName(getBeanArchiveIndex(), superType)
: null;
}
// non-inherited fields
for (FieldInfo field : beanClass.fields()) {
if (annotationStore.hasAnnotation(field, DotNames.PRODUCES)
&& !annotationStore.hasAnnotation(field, DotNames.VETOED_PRODUCER)) {
if (annotationStore.hasAnnotation(field, DotNames.INJECT)) {
throw new DefinitionException("Injected field cannot be annotated with @Produces: " + field);
}
// Do not register classes with producers and no bean def. annotation as beans in strict mode
// Producer fields are not inherited
if (strictCompatibility) {
if (hasBeanDefiningAnnotation) {
producerFields.add(field);
}
} else {
producerFields.add(field);
if (!hasBeanDefiningAnnotation) {
LOGGER.debugf("Producer field found but %s has no bean defining annotation - using @Dependent",
beanClass);
beanClasses.add(beanClass);
}
}
} else if (!annotationStore.hasAnnotation(field, DotNames.PRODUCES)) {
// Verify that non-producer fields are not annotated with stereotypes
// (vetoed producers must _not_ be checked)View on GitHub (pinned to e1c734241f)
Solutions
- Remove @Inject from the producer field and inject the needed dependencies elsewhere (e.g. constructor).
- If you actually want injection, remove @Produces instead.
- If the field must keep both for compatibility but should not be registered, mark it @VetoedProducer (or @Vetoed) to skip producer registration.
Example fix
// before @Inject @Produces Config config; // after @Produces Config config; // dependencies injected via constructor instead
Defensive patterns
Strategy: validation
Validate before calling
if (field.isAnnotationPresent(Inject.class) && field.isAnnotationPresent(Produces.class)) {
throw new IllegalStateException("@Inject and @Produces cannot both be on " + field);
} Prevention
- Never combine @Inject and @Produces on the same field
- Inject dependencies via constructor when writing producers
- Search codebase for fields carrying both annotations in review checklist
When it happens
Trigger: A field has both @Inject and @Produces annotations (and is not a @VetoedProducer); BeanDeployment.deploy iterates beanClass.fields() and detects the combination.
Common situations: Converting an injected field into a producer by adding @Produces without removing @Inject; copy-paste of annotation blocks; IDE quick-fixes stacking annotations.
Related errors
- Unsupported injection point target: <injectionPoint>
- Method ${method} of class ${beanClass} is not a producer met
- Field ${field} of class ${beanClass} is not a producer field
- Non-static public field ${field} present on normal scoped be
- No producer method or field declared by the bean class that
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/02b61b29dabe24dc.
Report an issue: GitHub.