{"record":{"id":"259430900e99792b","repo":"quarkusio/quarkus","slug":"resource-classes-that-use-field-injection-for-rest","errorCode":null,"errorMessage":"Resource classes that use field injection for REST parameters can only be @RequestScoped. Offending class is ${classInfo.name()}","messagePattern":"Resource classes that use field injection for REST parameters can only be @RequestScoped\\. Offending class is (.+?)","errorType":"exception","errorClass":"DeploymentException","httpStatus":null,"severity":"error","filePath":"extensions/resteasy-reactive/rest/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/QuarkusServerEndpointIndexer.java","lineNumber":293,"sourceCode":"            return;\n        }\n        super.warnAboutMissUsedBodyParameter(httpMethod, methodInfo);\n    }\n\n    /**\n     * At this point we know exactly which resources will require field injection and therefore are required to be\n     * {@link RequestScoped}.\n     * We can't change anything CDI related at this point (because it would create build cycles), so all we can do\n     * is fail the build if the resource has not already been handled automatically (by the best effort approach performed\n     * elsewhere)\n     * or it's not manually set to be {@link RequestScoped}.\n     */\n    @Override\n    protected void verifyClassThatRequiresFieldInjection(ClassInfo classInfo) {\n        if (!alreadyHandledRequestScopedResources.contains(classInfo.name())) {\n            BuiltinScope scope = BuiltinScope.from(classInfo);\n            if (BuiltinScope.REQUEST != scope) {\n                throw new DeploymentException(\n                        \"Resource classes that use field injection for REST parameters can only be @RequestScoped. Offending class is \"\n                                + classInfo.name());\n            }\n        }\n    }\n\n}\n","sourceCodeStart":275,"sourceCodeEnd":301,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/resteasy-reactive/rest/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/QuarkusServerEndpointIndexer.java#L275-L301","documentation":"RESTEasy Reactive supports REST parameter field injection (e.g. @QueryParam on fields) only in @RequestScoped resource classes, because the injected values are per-request. When the endpoint indexer detects a class needing field injection whose effective scope is not @RequestScoped, deployment fails with this DeploymentException.","triggerScenarios":"A resource class declares JAX-RS parameter annotations on fields (@QueryParam/@PathParam/@HeaderParam on instance fields) and the class is annotated with (or resolves to) a scope other than @RequestScoped — e.g. @Singleton or @ApplicationScoped.","commonSituations":"Marking resources @ApplicationScoped or @Singleton for perceived performance benefits while also using field injection of request parameters; migrating from classic RESTEasy where such combinations were tolerated differently.","solutions":["Annotate the resource class with @RequestScoped","Convert field injection to method parameter injection (move @QueryParam/@PathParam onto the resource method) and keep any scope you need","Use constructor injection with String-typed parameters instead of field injection","Remove the non-request scope annotation if the class should be request-scoped by default"],"exampleFix":"// before\n@ApplicationScoped\n@Path(\"/greet\")\npublic class GreetingResource {\n    @QueryParam(\"name\")\n    String name;\n}\n// after\n@RequestScoped\n@Path(\"/greet\")\npublic class GreetingResource {\n    @QueryParam(\"name\")\n    String name;\n}","handlingStrategy":"validation","validationCode":"// before build: resource uses field injection of REST params?\nboolean fieldInjection = Arrays.stream(resourceClass.getDeclaredFields())\n        .anyMatch(f -> Arrays.stream(f.getAnnotations()).anyMatch(a ->\n                a.annotationType().getName().startsWith(\"jakarta.ws.rs.\")));\nboolean requestScoped = resourceClass.isAnnotationPresent(jakarta.enterprise.context.RequestScoped.class);\nif (fieldInjection && !requestScoped)\n    throw new IllegalStateException(resourceClass + \" uses REST field injection and must be @RequestScoped\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always annotate resources that use REST parameter field injection with @RequestScoped","Prefer method-parameter injection so any CDI scope can be used","Never add @Singleton/@ApplicationScoped to resources relying on field injection","Document the scope requirement in team code-review guidelines"],"tags":["cdi","scope","jax-rs","resteasy-reactive","field-injection"],"backgroundTag":"field-injection-scope-violation","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}