quarkusio/quarkus · error · DefinitionException
Initializer method must not have an @Observes parameter (alt
Error message
Initializer method must not have an @Observes parameter (alternatively, observer method must not be annotated @Inject):
What it means
ArC throws this DefinitionException when an initializer (@Inject) method declares a parameter annotated @Observes — or a plain observer method annotated @Inject. Observer methods are discovered by their @Observes annotation and must not also be initializers; forBean validates initializer methods for parameter-level @Observes.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java:261
Set<MethodInfo> initializerMethods = injections.stream()
.filter(it -> it.isMethod() && !it.isConstructor())
.map(Injection::getTarget)
.map(AnnotationTarget::asMethod)
.collect(Collectors.toSet());
for (MethodInfo initializerMethod : initializerMethods) {
if (beanDeployment.hasAnnotation(initializerMethod, DotNames.PRODUCES)) {
throw new DefinitionException("Initializer method must not be annotated @Produces "
+ "(alternatively, producer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.DISPOSES)) {
throw new DefinitionException("Initializer method must not have a @Disposes parameter "
+ "(alternatively, disposer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES)) {
throw new DefinitionException("Initializer method must not have an @Observes parameter "
+ "(alternatively, observer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
if (Annotations.hasParameterAnnotation(beanDeployment, initializerMethod, DotNames.OBSERVES_ASYNC)) {
throw new DefinitionException("Initializer method must not have an @ObservesAsync parameter "
+ "(alternatively, async observer method must not be annotated @Inject): "
+ beanTarget.asClass() + "." + initializerMethod.name());
}
}
validateInjections(injections, beanType);
return injections;
} else if (Kind.METHOD.equals(beanTarget.kind())) {
MethodInfo producerMethod = beanTarget.asMethod();
if (beanDeployment.hasAnnotation(producerMethod, DotNames.INJECT)) {
throw new DefinitionException("Producer method must not be annotated @Inject "
+ "(alternatively, initializer method must not be annotated @Produces): "
+ producerMethod);View on GitHub (pinned to e1c734241f)
Solutions
- Remove @Observes from the initializer parameter and add a separate observer method
- If you need startup work, observe StartupEvent in a dedicated @Observes method inside the bean
- Keep the initializer for plain dependency injection only
- Rebuild; failure occurs at augmentation time
Example fix
// before
@Inject
void init(@Observes StartupEvent e) { setup(); }
// after
@Inject
void init() { }
void onStart(@Observes StartupEvent e) { setup(); } Defensive patterns
Strategy: validation
Validate before calling
void checkInitializer(Method m) {
if (!m.isAnnotationPresent(jakarta.inject.Inject.class)) return;
for (var p : m.getParameters()) {
if (p.isAnnotationPresent(jakarta.enterprise.event.Observes.class)) {
throw new IllegalStateException("@Observes on initializer param: " + m);
}
}
} Prevention
- Separate initialization (@Inject) from event handling (@Observes methods)
- Use a StartupEvent observer method for startup logic
- Never combine @Inject with observer/disposer parameter annotations
- Enable CDI validation in IDE for early feedback
When it happens
Trigger: An @Inject initializer method whose parameter is annotated @Observes (e.g. @Inject void init(@Observes MyEvent e)); caught by hasParameterAnnotation(initializerMethod, DotNames.OBSERVES) in forBean.
Common situations: Trying to react to events during bean initialization via an @Inject method; refactoring a standalone observer method into a bean's initializer; generated code combining @Inject with event handlers.
Related errors
- Bean constructor must not have an @Observes parameter:
- Initializer method must not have a @Disposes parameter (alte
- Initializer method must not have an @ObservesAsync parameter
- Producer method must not have an @Observes parameter (altern
- Bean constructor must not have a @Disposes parameter:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/2aaad08783893739.
Report an issue: GitHub.