quarkusio/quarkus · error · IllegalArgumentException
Unable to create class '{targetClassName}'. To fix the probl
Error message
Unable to create class '{targetClassName}'. To fix the problem, make sure this class is a CDI bean. What it means
ArcBeanFactory tried to instantiate a class through its CDI Arc instance factory, but creation failed and the factory used was a synthetic DefaultInstanceFactory — meaning the target class was never registered as a CDI bean. The original failure is wrapped in this IllegalArgumentException telling you to make the class a CDI bean.
Source
Thrown at extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcBeanFactory.java:41
@Override
public BeanInstance<T> createInstance() {
BeanContainer.Instance<T> instance;
try {
instance = factory.create();
return new BeanInstance<T>() {
@Override
public T getInstance() {
return instance.get();
}
@Override
public void close() {
instance.close();
}
};
} catch (Exception e) {
if (factory.getClass().getName().contains("DefaultInstanceFactory")) {
throw new IllegalArgumentException(
"Unable to create class '" + targetClassName
+ "'. To fix the problem, make sure this class is a CDI bean.",
e);
}
throw e;
}
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Add a bean-defining annotation to the class, e.g. `@ApplicationScoped`, `@RequestScoped`, or ensure it has `@Path` and is part of the app archive
- If you need all classes discovered, add an empty `beans.xml` with `bean-discovery-mode="all"`
- Check the wrapped cause `e` for the real instantiation error (missing constructor, checked exception in constructor, etc.)
Example fix
// before
public class MyResource { ... }
// after
@Path("/my")
@ApplicationScoped
public class MyResource { ... } Defensive patterns
Strategy: validation
Validate before calling
Class<?> c = MyResource.class; boolean beanDefining = c.isAnnotationPresent(Path.class) || c.isAnnotationPresent(ApplicationScoped.class) || c.isAnnotationPresent(RequestScoped.class); if (!beanDefining) throw new IllegalStateException("Class " + c + " needs a bean-defining annotation"); Try / catch
try { resource = arcBeanFactory.createInstance(MyResource.class); } catch (IllegalArgumentException e) { LOG.error("Not a CDI bean; check annotations", e.getCause()); throw e; } Prevention
- Annotate all JAX-RS resources with a bean-defining annotation (@Path, @ApplicationScoped)
- Avoid registering classes solely via Application.getClasses()
- If relying on all-class discovery, ship beans.xml with bean-discovery-mode=all
When it happens
Trigger: RESTEasy Reactive tries to create a resource/provider class not discovered by CDI (e.g. a JAX-RS resource missing a bean-defining annotation like @Path with proper discovery, or an @Application-supplied class not annotated and not in beans.xml).
Common situations: A resource class without any bean-defining annotation and no beans.xml beans discovery mode `all`; classes registered only via getClasses() in an Application; missing quarkus index of an external class.
Related errors
- Security annotation placed on resource method '${className}#
- Improper integration of '${LogFilterFactory.class.getName()}
- Unable to determine if bean '${className}' is available
- @AuthorizationPolicy annotation placed on resource method '$
- Security annotation placed on resource method '${className}#
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/a2fa30fbd45d2535.
Report an issue: GitHub.