{"record":{"id":"d241f46a9087aebb","repo":"apache/dubbo","slug":"any-annotation-of-s-can-t-be-annotated-in-the-s","errorCode":null,"errorMessage":"Any annotation of [%s] can't be annotated in the service type[%s].","messagePattern":"Any annotation of \\[(.+?)\\] can't be annotated in the service type\\[(.+?)\\]\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/ServiceAnnotationResolver.java","lineNumber":80,"sourceCode":"\n    public ServiceAnnotationResolver(Class<?> serviceType) throws IllegalArgumentException {\n        this.serviceType = serviceType;\n        this.serviceAnnotation = getServiceAnnotation(serviceType);\n    }\n\n    private Annotation getServiceAnnotation(Class<?> serviceType) {\n\n        Annotation serviceAnnotation = null;\n\n        for (Class<? extends Annotation> serviceAnnotationClass : SERVICE_ANNOTATION_CLASSES) {\n            serviceAnnotation = serviceType.getAnnotation(serviceAnnotationClass);\n            if (serviceAnnotation != null) {\n                break;\n            }\n        }\n\n        if (serviceAnnotation == null) {\n            throw new IllegalArgumentException(format(\n                    \"Any annotation of [%s] can't be annotated in the service type[%s].\",\n                    SERVICE_ANNOTATION_CLASSES, serviceType.getName()));\n        }\n\n        return serviceAnnotation;\n    }\n\n    /**\n     * Resolve the class name of interface\n     *\n     * @return if not found, return <code>null</code>\n     */\n    public String resolveInterfaceClassName() {\n\n        Class interfaceClass;\n        // first, try to get the value from \"interfaceName\" attribute\n        String interfaceName = resolveAttribute(\"interfaceName\");\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ServiceAnnotationResolver.java#L62-L98","documentation":"Thrown by ServiceAnnotationResolver when constructing a resolver for a class that carries none of the recognized service annotations (@DubboService or @Service). The resolver iterates SERVICE_ANNOTATION_CLASSES and throws IllegalArgumentException if no match is found. The message names the expected annotations and the offending service type.","triggerScenarios":"Calling new ServiceAnnotationResolver(myClass) where myClass has neither @DubboService nor @org.apache.dubbo.config.annotation.Service (or the legacy com.alibaba variant when compact mode is enabled). Common when auto-scanning picks up a class that was meant to be a plain bean.","commonSituations":"Service class uses a custom or deprecated annotation; annotation was removed or commented out during refactoring; classpath has an old Dubbo version where annotation package differs (com.alibaba vs org.apache); component scan range is too broad and includes non-service classes.","solutions":["Annotate the class with @DubboService (or @Service for the Dubbo-native one) at the class level.","If using the legacy API, ensure com.alibaba.dubbo.config.annotation.Service is on the classpath and compact mode is enabled.","Narrow the component-scan basePackages so only intended service classes reach the resolver."],"exampleFix":"// before\npublic class OrderServiceImpl implements OrderService { ... }\n\n// after\n@DubboService\npublic class OrderServiceImpl implements OrderService { ... }","handlingStrategy":"validation","validationCode":"boolean hasServiceAnnotation = ServiceAnnotationResolver.SERVICE_ANNOTATION_CLASSES\n    .stream()\n    .anyMatch(ann -> serviceType.getAnnotation(ann) != null);\nif (!hasServiceAnnotation) {\n    // annotate the class or exclude it from scanning\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure every class in the component-scan range has @DubboService if it should be exported.","Narrow basePackages to avoid passing plain beans to ServiceAnnotationResolver."],"tags":["annotation","service-discovery","configuration","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}