{"record":{"id":"a2fa30fbd45d2535","repo":"quarkusio/quarkus","slug":"unable-to-create-class-targetclassname-to-fix","errorCode":null,"errorMessage":"Unable to create class '{targetClassName}'. To fix the problem, make sure this class is a CDI bean.","messagePattern":"Unable to create class '(.+?)'\\. To fix the problem, make sure this class is a CDI bean\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcBeanFactory.java","lineNumber":41,"sourceCode":"    @Override\n    public BeanInstance<T> createInstance() {\n        BeanContainer.Instance<T> instance;\n        try {\n            instance = factory.create();\n            return new BeanInstance<T>() {\n                @Override\n                public T getInstance() {\n                    return instance.get();\n                }\n\n                @Override\n                public void close() {\n                    instance.close();\n                }\n            };\n        } catch (Exception e) {\n            if (factory.getClass().getName().contains(\"DefaultInstanceFactory\")) {\n                throw new IllegalArgumentException(\n                        \"Unable to create class '\" + targetClassName\n                                + \"'. To fix the problem, make sure this class is a CDI bean.\",\n                        e);\n            }\n            throw e;\n        }\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":50,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/resteasy-reactive/rest-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcBeanFactory.java#L23-L50","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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.)"],"exampleFix":"// before\npublic class MyResource { ... }\n// after\n@Path(\"/my\")\n@ApplicationScoped\npublic class MyResource { ... }","handlingStrategy":"validation","validationCode":"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\");","typeGuard":null,"tryCatchPattern":"try { resource = arcBeanFactory.createInstance(MyResource.class); } catch (IllegalArgumentException e) { LOG.error(\"Not a CDI bean; check annotations\", e.getCause()); throw e; }","preventionTips":["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"],"tags":["cdi","bean-discovery","resteasy-reactive","quarkus"],"backgroundTag":"cdi-bean-not-discovered","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}