quarkusio/quarkus · error · DefinitionException
Multiple @PostConstruct interceptor methods declared on clas
Error message
Multiple @PostConstruct interceptor methods declared on class:
What it means
ArC throws this DefinitionException when an interceptor class (or any one class in its hierarchy) declares more than one non-static method annotated with @PostConstruct. The CDI specification allows at most one @PostConstruct lifecycle callback interceptor method per interceptor class. The error is raised during build-time bean discovery, preventing the application from starting.
Source
Thrown at independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InterceptorInfo.java:134
InterceptorPlacement.INTERCEPTOR_CLASS);
if (++aroundInvokesFound > 1) {
throw new DefinitionException(
"Multiple @AroundInvoke interceptor methods declared on class: " + aClass);
}
}
if (store.hasAnnotation(method, DotNames.AROUND_CONSTRUCT)) {
addInterceptorMethod(allMethods, aroundConstructs, method, InterceptionType.AROUND_CONSTRUCT,
InterceptorPlacement.INTERCEPTOR_CLASS);
if (++aroundConstructsFound > 1) {
throw new DefinitionException(
"Multiple @AroundConstruct interceptor methods declared on class: " + aClass);
}
}
if (store.hasAnnotation(method, DotNames.POST_CONSTRUCT)) {
addInterceptorMethod(allMethods, postConstructs, method, InterceptionType.POST_CONSTRUCT,
InterceptorPlacement.INTERCEPTOR_CLASS);
if (++postConstructsFound > 1) {
throw new DefinitionException(
"Multiple @PostConstruct interceptor methods declared on class: " + aClass);
}
}
if (store.hasAnnotation(method, DotNames.PRE_DESTROY)) {
addInterceptorMethod(allMethods, preDestroys, method, InterceptionType.PRE_DESTROY,
InterceptorPlacement.INTERCEPTOR_CLASS);
if (++preDestroysFound > 1) {
throw new DefinitionException(
"Multiple @PreDestroy interceptor methods declared on class: " + aClass);
}
}
allMethods.add(method);
}
for (FieldInfo field : aClass.fields()) {
if (store.hasAnnotation(field, DotNames.PRODUCES)) {
// according to spec, finding @Produces on a field is a DefinitionException
throw new DefinitionException(View on GitHub (pinned to e1c734241f)
Solutions
- Keep a single @PostConstruct method and call the other initialization methods from it as plain helpers.
- Remove the @PostConstruct annotation from the redundant method.
- Use @ApplicationScoped/@Dependent bean lifecycle callbacks elsewhere, or split into multiple interceptor classes.
Example fix
// before
class MyInterceptor {
@PostConstruct void init1(InvocationContext ctx) throws Exception { ctx.proceed(); }
@PostConstruct void init2(InvocationContext ctx) throws Exception { ctx.proceed(); }
}
// after
class MyInterceptor {
@PostConstruct void init(InvocationContext ctx) throws Exception { extraInit(); ctx.proceed(); }
void extraInit() { /* ... */ }
} Defensive patterns
Strategy: validation
Validate before calling
long n = java.util.Arrays.stream(MyInterceptor.class.getDeclaredMethods())
.filter(m -> m.isAnnotationPresent(jakarta.annotation.PostConstruct.class))
.count();
if (n > 1) throw new IllegalStateException("Only one @PostConstruct allowed per interceptor class"); Prevention
- One @PostConstruct per class; chain other init methods from it
- When migrating from Spring-style multiple init methods, consolidate them first
- Audit superclasses: each class level may hold one callback, but one class may not hold two
When it happens
Trigger: Two or more non-static methods annotated with @PostConstruct in the same interceptor class. The count resets for each class in the hierarchy, so one per class across superclass/subclass is permitted.
Common situations: Migrating from Spring (where multiple @PostConstruct-like init methods were tolerated via @Bean initMethod) to CDI; merging interceptor classes; copy-paste during refactoring.
Related errors
- Multiple @PreDestroy interceptor methods declared on class:
- Multiple @AroundInvoke interceptor methods declared on class
- Multiple @AroundConstruct interceptor methods declared on cl
- An interceptor field cannot be marked @Produces -
- interceptor method validation message (dynamically built: mu
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/8ad259e55e6e6be9.
Report an issue: GitHub.