quarkusio/quarkus · error · ContextNotActiveException

No active context found for: ${scopeType}

Error message

No active context found for: ${scopeType}

What it means

BeanManagerImpl.getContext() delegates to Arc.requireContainer().getActiveContext(scopeType) and throws ContextNotActiveException when no context for the requested scope is currently active. This is the standard CDI signal that you are touching a scoped bean outside its active context (e.g. request-scoped code outside a request).

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/BeanManagerImpl.java:228

    public boolean areInterceptorBindingsEquivalent(Annotation interceptorBinding1, Annotation interceptorBinding2) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int getQualifierHashCode(Annotation qualifier) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int getInterceptorBindingHashCode(Annotation interceptorBinding) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Context getContext(Class<? extends Annotation> scopeType) {
        Context context = Arc.requireContainer().getActiveContext(scopeType);
        if (context == null) {
            throw new ContextNotActiveException("No active context found for: " + scopeType);
        }
        return context;
    }

    @Override
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public Collection<Context> getContexts(Class<? extends Annotation> scopeType) {
        return (Collection) Arc.requireContainer().getContexts(scopeType);
    }

    @Override
    public ELResolver getELResolver() {
        throw new UnsupportedOperationException();
    }

    @Override
    public ExpressionFactory wrapExpressionFactory(ExpressionFactory expressionFactory) {
        throw new UnsupportedOperationException();

View on GitHub (pinned to e1c734241f)

Solutions

  1. Run the code inside the appropriate context (e.g. activate RequestScoped context via Arc.container().requestContext().activate() / terminate)
  2. Change the bean's scope to @ApplicationScoped (or another always-active scope) if per-request state is not needed
  3. Pass required data explicitly instead of reading request-scoped beans from background threads
  4. In Quarkus messaging/scheduler code, use @ActivateRequestContext on the method that touches the scoped bean

Example fix

// before
@Scheduled(every = "10s")
void run() { requestScopedBean.doWork(); } // context not active

// after
@Scheduled(every = "10s")
@ActivateRequestContext
void run() { requestScopedBean.doWork(); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (Arc.container().getActiveContext(RequestScoped.class) == null) {
    LOGGER.warn("Request context not active; activating");
    Arc.container().requestContext().activate();
}

Try / catch

try {
    Context ctx = bm.getContext(RequestScoped.class);
    ...
} catch (ContextNotActiveException e) {
    Arc.container().requestContext().activate();
    try { ... } finally { Arc.container().requestContext().terminate(); }
}

Prevention

When it happens

Trigger: Calling getContext(RequestScoped.class) (or accessing a @RequestScoped/@SessionScoped bean) from a background thread, @Scheduled task, startup event, Vert.x worker, or any place where the scope's context was never activated.

Common situations: ApplicationScope vs request scope confusion in async code; accessing RequestScoped beans from Kafka/AMQP message consumers, gRPC worker threads, or executors; code run before/after the HTTP request ends; tests without quarkus test request setup.

Related errors


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