quarkusio/quarkus · error · DefinitionException

Method ${method} of class ${beanClass} is not a producer met

Error message

Method ${method} of class ${beanClass} is not a producer method, but is annotated with a stereotype: ${stereotype}

What it means

This is a ArC (Quarkus CDI) DefinitionException thrown during bean discovery. CDI stereotypes (annotation types annotated @Stereotype) may only be applied to beans and producer methods/fields. Applying a real stereotype to a regular method that is not a producer method is invalid, so the container rejects the deployment.

Source

Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java:1255

            ClassInfo aClass = beanClass;
            Set<MethodSignatureKey> methods = new HashSet<>();
            while (aClass != null) {
                for (MethodInfo method : aClass.methods()) {
                    MethodSignatureKey methodKey = method.signatureKey();
                    if (method.isSynthetic() || Methods.isOverridden(methodKey, methods)) {
                        continue;
                    }
                    methods.add(methodKey);
                    Collection<AnnotationInstance> methodAnnotations = annotationStore.getAnnotations(method);
                    if (methodAnnotations.isEmpty()) {
                        continue;
                    }
                    // Verify that non-producer methods are not annotated with stereotypes
                    // only account for 'real' stereotypes that are not additional BeanDefiningAnnotations
                    if (!annotationStore.hasAnnotation(method, DotNames.PRODUCES)) {
                        for (AnnotationInstance i : methodAnnotations) {
                            if (realStereotypes.contains(i.name())) {
                                throw new DefinitionException(
                                        "Method " + method + " of class " + beanClass
                                                + " is not a producer method, but is annotated " +
                                                "with a stereotype: " + i.name().toString());
                            }
                        }
                    }
                    if (annotationStore.hasAnnotation(method, DotNames.OBSERVES)) {
                        syncObserverMethods.computeIfAbsent(method, ignored -> new HashSet<>())
                                .add(beanClass);
                        // add only concrete classes
                        if (!Modifier.isAbstract(beanClass.flags())) {
                            // do not register classes with observers and no bean def. annotation as beans in strict mode
                            if (!strictCompatibility) {
                                beanClasses.add(beanClass);
                                if (!hasBeanDefiningAnnotation) {
                                    LOGGER.debugf(
                                            "Observer method found but %s has no bean defining annotation - using @Dependent",
                                            beanClass);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove the stereotype annotation from the non-producer method, or annotate it as a stereotype meta-annotation only on classes.
  2. If the method was meant to produce a bean, add @Produces so the stereotype becomes legal.
  3. If you authored the stereotype, re-check its @Target (it should target TYPE/FIELD/METHOD as intended) and restrict usage.

Example fix

// before
class Repo {
  @Transactional
  User findUser(long id) { ... } // not a producer
}
// after
class Repo {
  @Produces
  @Transactional
  User findUser(long id) { ... }
}
// or simply remove @Transactional
Defensive patterns

Strategy: validation

Validate before calling

// Before build/deploy: reject stereotypes on non-producer methods
if (method.isAnnotationPresent(StereotypeDerived.class) && !method.isAnnotationPresent(Produces.class)) {
    throw new IllegalStateException("Stereotype on non-producer method: " + method);
}

Prevention

When it happens

Trigger: A method on a bean-defining class carries a stereotype annotation (from a registered @Stereotype) but is not annotated @Produces; BeanDeployment.deploy/bean registration scans method annotations and finds the stereotype in realStereotypes (excluding additional BeanDefiningAnnotations).

Common situations: Copying a stereotype like @Transactional or a custom @Stereotype onto a private helper or initializer method; a refactoring removed @Produces but left the stereotype; misunderstanding stereotypes as generic markers applicable anywhere.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/baf41c16ab061a7a. Report an issue: GitHub.