{"record":{"id":"ef7612087f63e1a3","repo":"apache/dubbo","slug":"service-servicekey-target-is-null","errorCode":null,"errorMessage":"Service[<serviceKey>]Target is NULL.","messagePattern":"Service\\[<serviceKey>\\]Target is NULL\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java","lineNumber":52,"sourceCode":"public class ProviderModel extends ServiceModel {\n    private final List<RegisterStatedURL> urls;\n    private final Map<String, List<ProviderMethodModel>> methods = new HashMap<>();\n\n    /**\n     * The url of the reference service\n     */\n    private List<URL> serviceUrls = new ArrayList<>();\n\n    private volatile long lastInvokeTime = 0;\n\n    public ProviderModel(\n            String serviceKey,\n            Object serviceInstance,\n            ServiceDescriptor serviceDescriptor,\n            ClassLoader interfaceClassLoader) {\n        super(serviceInstance, serviceKey, serviceDescriptor, null, interfaceClassLoader);\n        if (null == serviceInstance) {\n            throw new IllegalArgumentException(\"Service[\" + serviceKey + \"]Target is NULL.\");\n        }\n\n        this.urls = new CopyOnWriteArrayList<>();\n    }\n\n    public ProviderModel(\n            String serviceKey,\n            Object serviceInstance,\n            ServiceDescriptor serviceDescriptor,\n            ServiceMetadata serviceMetadata,\n            ClassLoader interfaceClassLoader) {\n        super(serviceInstance, serviceKey, serviceDescriptor, null, serviceMetadata, interfaceClassLoader);\n        if (null == serviceInstance) {\n            throw new IllegalArgumentException(\"Service[\" + serviceKey + \"]Target is NULL.\");\n        }\n\n        initMethod(serviceDescriptor.getServiceInterfaceClass());\n        this.urls = new ArrayList<>(1);","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ProviderModel.java#L34-L70","documentation":"The first ProviderModel constructor (4-arg) validates that the service implementation object (serviceInstance) is non-null before building the provider model. A provider in Dubbo must wrap a real bean instance that will receive RPC invocations, so a null target is a fatal configuration error caught at registration time. The message embeds the serviceKey so you can identify which interface was misconfigured.","triggerScenarios":"Constructing `new ProviderModel(serviceKey, null, serviceDescriptor, interfaceClassLoader)` — i.e. passing a null service bean. Typically reached when a ServiceConfig is exported with a ref that resolved to null (bean not found in the Spring context, lazy-init bean still null, or programmatic export with no setRef).","commonSituations":"Spring XML/annotation config where @Service(ref=...) or <dubbo:service ref=...> references a bean name that does not exist or was not yet instantiated. Programmatic ServiceConfig.export() where setRef() was never called. AOP/proxy misconfiguration that returns null from the bean factory. Migration where the ref bean id was renamed but the dubbo:service reference was not updated.","solutions":["Ensure the service implementation bean exists and is injected before export: verify the ref passed to ServiceConfig.setRef() / the <dubbo:service ref> attribute resolves to a non-null instance.","If exporting programmatically, call serviceConfig.setRef(myServiceImpl) with a concrete, already-constructed object.","Check Spring context startup logs for 'no bean named' warnings and fix bean naming/scan-path issues before Dubbo export runs.","Add a null-check on the ref in your export bootstrap so the failure is reported with your own context, not deep inside ProviderModel."],"exampleFix":"// before\nServiceConfig<HelloService> sc = new ServiceConfig<>();\nsc.setInterface(HelloService.class);\n// setRef forgotten -> serviceInstance null -> throws at registration\nsc.export();\n\n// after\nHelloService impl = applicationContext.getBean(HelloService.class);\nServiceConfig<HelloService> sc = new ServiceConfig<>();\nsc.setInterface(HelloService.class);\nsc.setRef(impl);\nsc.export();","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(serviceInstance, \"serviceInstance for \" + serviceKey);\nnew ProviderModel(serviceKey, serviceInstance, serviceDescriptor, interfaceClassLoader);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call ServiceConfig.setRef(...) with a concrete, non-null bean before export().","Resolve Spring beans explicitly and assert non-null in your bootstrap before passing to Dubbo.","Verify @DubboService/@Service targets a real, scanned bean."],"tags":["provider","service-config","null-ref","registration"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}