apache/dubbo · error · IllegalArgumentException

Any annotation of [%s] can't be annotated in the service typ

Error message

Any annotation of [%s] can't be annotated in the service type[%s].

What it means

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.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/ServiceAnnotationResolver.java:80

    public ServiceAnnotationResolver(Class<?> serviceType) throws IllegalArgumentException {
        this.serviceType = serviceType;
        this.serviceAnnotation = getServiceAnnotation(serviceType);
    }

    private Annotation getServiceAnnotation(Class<?> serviceType) {

        Annotation serviceAnnotation = null;

        for (Class<? extends Annotation> serviceAnnotationClass : SERVICE_ANNOTATION_CLASSES) {
            serviceAnnotation = serviceType.getAnnotation(serviceAnnotationClass);
            if (serviceAnnotation != null) {
                break;
            }
        }

        if (serviceAnnotation == null) {
            throw new IllegalArgumentException(format(
                    "Any annotation of [%s] can't be annotated in the service type[%s].",
                    SERVICE_ANNOTATION_CLASSES, serviceType.getName()));
        }

        return serviceAnnotation;
    }

    /**
     * Resolve the class name of interface
     *
     * @return if not found, return <code>null</code>
     */
    public String resolveInterfaceClassName() {

        Class interfaceClass;
        // first, try to get the value from "interfaceName" attribute
        String interfaceName = resolveAttribute("interfaceName");

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Annotate the class with @DubboService (or @Service for the Dubbo-native one) at the class level.
  2. If using the legacy API, ensure com.alibaba.dubbo.config.annotation.Service is on the classpath and compact mode is enabled.
  3. Narrow the component-scan basePackages so only intended service classes reach the resolver.

Example fix

// before
public class OrderServiceImpl implements OrderService { ... }

// after
@DubboService
public class OrderServiceImpl implements OrderService { ... }
Defensive patterns

Strategy: validation

Validate before calling

boolean hasServiceAnnotation = ServiceAnnotationResolver.SERVICE_ANNOTATION_CLASSES
    .stream()
    .anyMatch(ann -> serviceType.getAnnotation(ann) != null);
if (!hasServiceAnnotation) {
    // annotate the class or exclude it from scanning
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/d241f46a9087aebb. Report an issue: GitHub.