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

  1. Add a bean-defining annotation to the class, e.g. `@ApplicationScoped`, `@RequestScoped`, or ensure it has `@Path` and is part of the app archive
  2. If you need all classes discovered, add an empty `beans.xml` with `bean-discovery-mode="all"`
  3. 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

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


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