{"record":{"id":"5892d9b1f1a9b56a","repo":"apache/shenyu","slug":"tars-client-must-config-the-contextpath-ipandport","errorCode":null,"errorMessage":"tars client must config the contextPath, ipAndPort","messagePattern":"tars client must config the contextPath, ipAndPort","errorType":"exception","errorClass":"ShenyuClientIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java","lineNumber":76,"sourceCode":" * The Tars ServiceBean EventListener.\n */\npublic class TarsServiceBeanEventListener extends AbstractContextRefreshedEventListener<Object, ShenyuTarsClient> {\n\n    private final StandardReflectionParameterNameDiscoverer localVariableTableParameterNameDiscoverer = new StandardReflectionParameterNameDiscoverer();\n\n    private final ShenyuClientRegisterEventPublisher publisher = ShenyuClientRegisterEventPublisher.getInstance();\n\n    private final String contextPath;\n\n    private final String ipAndPort;\n\n    public TarsServiceBeanEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {\n        super(clientConfig, shenyuClientRegisterRepository);\n        Properties props = clientConfig.getClient().get(getClientName()).getProps();\n        String contextPath = props.getProperty(ShenyuClientConstants.CONTEXT_PATH);\n        String port = props.getProperty(ShenyuClientConstants.PORT);\n        if (StringUtils.isAnyBlank(contextPath, this.getHost(), port)) {\n            throw new ShenyuClientIllegalArgumentException(\"tars client must config the contextPath, ipAndPort\");\n        }\n        this.contextPath = contextPath;\n        this.ipAndPort = this.getHost() + \":\" + port;\n        publisher.start(shenyuClientRegisterRepository);\n    }\n\n    @Override\n    protected Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, String> buildApiDocSextet(final Method method, final Annotation annotation, final Map<String, Object> beans) {\n        ShenyuTarsClient shenyuTarsClient = AnnotatedElementUtils.findMergedAnnotation(method, ShenyuTarsClient.class);\n        if (Objects.isNull(shenyuTarsClient)) {\n            return null;\n        }\n        String produce = ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE;\n        String consume = ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE;\n        String[] values = new String[]{shenyuTarsClient.value()};\n        ApiHttpMethodEnum[] apiHttpMethodEnums = new ApiHttpMethodEnum[]{ApiHttpMethodEnum.NOT_HTTP};\n        String version = \"v0.01\";\n        return Sextet.with(values, consume, produce, apiHttpMethodEnums, RpcTypeEnum.TARS, version);","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-client/shenyu-client-tars/src/main/java/org/apache/shenyu/client/tars/TarsServiceBeanEventListener.java#L58-L94","documentation":"TarsServiceBeanEventListener validates at startup that the Tars client has a non-blank contextPath, host, and port configured under shenyu.client.tars.props. If any of these is missing or empty, the client cannot build the registration metadata (rpcType/contextPath/ipAndPort) needed to register the Tars service with shenyu-admin, so construction fails fast with ShenyuClientIllegalArgumentException.","triggerScenarios":"Constructing TarsServiceBeanEventListener when the Properties from clientConfig.getClient().get(clientName).getProps() lack 'contextPath' or 'port', or when the resolved host is blank (e.g. shenyu.client.tars.register.* host settings absent).","commonSituations":"Spring Boot application.yml missing shenyu.client.tars.props.context-path or props.port keys; copying a config from another rpcType sample that used different prop names; running in a container where the host cannot be auto-detected and none was configured.","solutions":["Add shenyu.client.tars.props.contextPath (e.g. /tars) and shenyu.client.tars.props.port (e.g. 8123) to application.yml or the XML properties for the client.","Verify the register section (serverLists, and host/thrift ip settings) is present so this.getHost() resolves to a non-blank value.","Confirm the properties are under the correct client name key matching getClientName() (tars), not under another rpcType block.","Restart the application after editing config; this check runs only during bean-listener construction."],"exampleFix":"// before (application.yml)\nshenyu:\n  client:\n    tars:\n      props: {}\n// after\nshenyu:\n  client:\n    tars:\n      register:\n        serverLists: http://localhost:9095\n      props:\n        contextPath: /tars\n        port: 8123","handlingStrategy":"validation","validationCode":"Properties props = clientConfig.getClient().get(\"tars\").getProps();\nif (StringUtils.isAnyBlank(props.getProperty(\"contextPath\"), props.getProperty(\"port\"))) {\n    throw new IllegalStateException(\"tars client requires props.contextPath and props.port\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    new TarsServiceBeanEventListener(clientConfig, repo);\n} catch (ShenyuClientIllegalArgumentException e) {\n    LOG.error(\"Tars client misconfigured: {}\", e.getMessage());\n}","preventionTips":["Keep a shared application.yml template including contextPath and port for every rpcType client.","Add a startup config validator test that asserts required props exist per rpcType."],"tags":["config","tars","startup","client-registration"],"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"}