{"record":{"id":"4d4b3ec271805239","repo":"apache/shenyu","slug":"client-register-param-must-config-the-appname-or-contextpath","errorCode":null,"errorMessage":"client register param must config the appName or contextPath","messagePattern":"client register param must config the appName or contextPath","errorType":"exception","errorClass":"ShenyuClientIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java","lineNumber":134,"sourceCode":"    public AbstractContextRefreshedEventListener(final ShenyuClientConfig clientConfig,\n                                                 final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {\n        ClientPropertiesConfig config = clientConfig.getClient().get(getClientName());\n        if (Objects.isNull(config)) {\n            throw new ShenyuClientIllegalArgumentException(\"clientConfig must config \" + getClientName() + \" properties\");\n        }\n        Properties props = config.getProps();\n        String namespace = clientConfig.getNamespace();\n        if (StringUtils.isBlank(namespace)) {\n            LOG.warn(\"current shenyu.namespace is null, use default namespace: {}\", Constants.SYS_DEFAULT_NAMESPACE_ID);\n            namespace = Constants.SYS_DEFAULT_NAMESPACE_ID;\n        }\n        this.namespace = Lists.newArrayList(StringUtils.split(namespace, Constants.SEPARATOR_CHARS));\n        this.appName = props.getProperty(ShenyuClientConstants.APP_NAME);\n        this.contextPath = Optional.ofNullable(props.getProperty(ShenyuClientConstants.CONTEXT_PATH)).map(UriUtils::repairData).orElse(\"\");\n        if (StringUtils.isBlank(appName) && StringUtils.isBlank(contextPath)) {\n            String errorMsg = \"client register param must config the appName or contextPath\";\n            LOG.error(errorMsg);\n            throw new ShenyuClientIllegalArgumentException(errorMsg);\n        }\n        this.ipAndPort = props.getProperty(ShenyuClientConstants.IP_PORT);\n        this.host = props.getProperty(ShenyuClientConstants.HOST);\n        this.port = props.getProperty(ShenyuClientConstants.PORT);\n        publisher.start(shenyuClientRegisterRepository);\n    }\n\n    @Override\n    public void onApplicationEvent(@NonNull final ContextRefreshedEvent event) {\n        context = event.getApplicationContext();\n        Map<String, T> beans = getBeans(context);\n        if (MapUtils.isEmpty(beans)) {\n            return;\n        }\n        if (!markRegistered()) {\n            return;\n        }\n        String discoveryMode = context.getEnvironment()","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java#L116-L152","documentation":"The same constructor validates that at least one of appName or contextPath is set in the client props; if both are blank it throws ShenyuClientIllegalArgumentException with this fixed message. ShenYu needs one of them to build the client registration (RPC type/context path) sent to the admin.","triggerScenarios":"Constructing the listener when props from shenyu.<clientName>.props lack both appName and contextPath — e.g. empty props map or only unrelated keys present.","commonSituations":"New service onboarded with only register address configured and no props; contextPath typo'd (e.g. context-path); props nested under the wrong client key so they're never read; config trimmed down during cleanup.","solutions":["Set contextPath (and typically appName) under shenyu.<clientName>.props in application.yml","Check for key typos — the properties must be named appName and contextPath exactly","Verify the props block is under the correct client name key matching the starter in use","Restart the client app so the refreshed context picks up the new properties"],"exampleFix":"// before\nshenyu:\n  client:\n    http:\n      props: {}\n// after\nshenyu:\n  client:\n    http:\n      props:\n        contextPath: /myapi\n        appName: myapi\n        port: 8181","handlingStrategy":"validation","validationCode":"// pre-check props before startup\nProperties props = /* shenyu.client.<name>.props */;\nString appName = props.getProperty(\"appName\");\nString contextPath = props.getProperty(\"contextPath\");\nif ((appName == null || appName.isBlank()) && (contextPath == null || contextPath.isBlank())) {\n    throw new IllegalStateException(\"set appName or contextPath in shenyu client props\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    context.refresh();\n} catch (ShenyuClientIllegalArgumentException e) {\n    log.error(\"Registration config invalid: {}\", e.getMessage());\n    // add appName/contextPath and restart\n}","preventionTips":["Always set contextPath in shenyu.<client>.props for new services","Use exact key names appName and contextPath (no kebab-case)","Validate the full client props block in CI config checks"],"tags":["configuration","client","registration","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}