{"record":{"id":"4283285617818dac","repo":"quarkusio/quarkus","slug":"components-annotated-with-multiple-conflicting-sco","errorCode":null,"errorMessage":"Components annotated with multiple conflicting scopes must declare an explicit @Scope. <class> declares scopes: <scopes> through the stereotypes: <stereotypes>","messagePattern":"Components annotated with multiple conflicting scopes must declare an explicit @Scope\\. <class> declares scopes: <scopes> through the stereotypes: <stereotypes>","errorType":"exception","errorClass":"DefinitionException","httpStatus":null,"severity":"error","filePath":"extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java","lineNumber":636,"sourceCode":"    /**\n     * Get a single scope from the available options or throw a {@link DefinitionException} explaining\n     * where the annotations conflict.\n     *\n     * @param clazz The class annotated with the scopes\n     * @param scopes The scopes from the class and its stereotypes\n     * @param scopeStereotypes The stereotype annotations that declared the conflicting scopes\n     * @return The scope for the target class\n     */\n    private DotName validateScope(final ClassInfo clazz, final Set<DotName> scopes, final Set<DotName> scopeStereotypes) {\n        final int size = scopes.size();\n        switch (size) {\n            case 0:\n                // Spring default\n                return CDI_SINGLETON_ANNOTATION;\n            case 1:\n                return scopes.iterator().next();\n            default:\n                throw new DefinitionException(\n                        \"Components annotated with multiple conflicting scopes must declare an explicit @Scope. \"\n                                + clazz.name() + \" declares scopes: \"\n                                + scopes.stream().map(DotName::toString).collect(Collectors.joining(\", \"))\n                                + \" through the stereotypes: \"\n                                + scopeStereotypes.stream().map(DotName::toString)\n                                        .collect(Collectors.joining(\", \")));\n        }\n    }\n\n    /**\n     * Get the name of a bean or throw a {@link DefinitionException} if it has more than one name\n     *\n     * @param clazz The class annotated with the names\n     * @param names The names\n     * @return The bane name\n     */\n    private String validateName(final ClassInfo clazz, final Set<String> names) {\n        final int size = names.size();","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java#L618-L654","documentation":"A Spring bean uses multiple scope-carrying annotations (e.g. via custom stereotype/composed annotations) that each declare a different scope, so the translated CDI bean has ambiguous scope. The Spring DI processor requires an explicit @Scope on the class to disambiguate.","triggerScenarios":"Annotating a @Component/@Service class with two or more annotations whose meta-annotations declare different scopes (e.g. a @Transactional-style stereotype plus a request-scoped stereotype) without an explicit @Scope on the class.","commonSituations":"Migrating Spring projects that define custom stereotype annotations with meta-scopes; accidentally stacking scope-bearing annotations; copy-pasted annotations on service classes.","solutions":["Add an explicit @Scope (e.g. @Scope(\"singleton\") or @Scope(\"prototype\")) to the class","Remove one of the conflicting scope-bearing stereotype annotations","Refactor the stereotypes so all declare the same scope"],"exampleFix":"// before\n@Component\n@MyTransactionalStereotype\n@MyRequestStereotype\nclass MyService {}\n\n// after\n@Component\n@Scope(\"prototype\")\n@MyTransactionalStereotype\n@MyRequestStereotype\nclass MyService {}","handlingStrategy":"validation","validationCode":"Set<Annotation> scopes = getScopeBearingAnnotations(clazz);\nif (scopes.stream().map(s -> resolveScope(s)).distinct().count() > 1 && !clazz.isAnnotationPresent(Scope.class)) {\n    throw new IllegalStateException(\"Add explicit @Scope to \" + clazz.getName());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep at most one scope-bearing stereotype per component","Always declare @Scope explicitly when using multiple stereotypes","Document custom stereotypes' scopes to avoid conflicts"],"tags":["spring-di","scope","cdi","stereotype","quarkus"],"backgroundTag":"ambiguous-bean-scope","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"}