You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/05/22 02:40:32 UTC
[GitHub] [servicecomb-java-chassis] yhs0092 commented on issue #1213: rpc提供方方法重名,消费方调用时,会报方法名找不到的错误
yhs0092 commented on issue #1213: rpc提供方方法重名,消费方调用时,会报方法名找不到的错误
URL: https://github.com/apache/servicecomb-java-chassis/issues/1213#issuecomment-494630085
按照你的描述,我尝试复现了一下问题
服务端REST 接口类定义:
```java
@RestSchema(schemaId = "RpcApi")
public class RpcApi {
private static final Logger LOGGER = LoggerFactory.getLogger(RpcApi.class);
@ApiOperation(value = "", nickname = "sayHi")
public void sayHi() {//do something
LOGGER.info("sayHi!!!");
}
@ApiOperation(value = "", nickname = "sayHiWithParam")
public void sayHi(String content) {//do something
LOGGER.info("sayHi[{}]", content);
}
}
```
客户端定义服务端接口代码:
```java
public interface RpcApi {
void sayHi();
void sayHiWithParam(String content);
}
```
客户端调用代码:
```java
@RpcReference(microserviceName = "provider", schemaId = "RpcApi")
RpcApi rpcApi;
@Path("test")
@GET
public String test() {
String result = "";
rpcApi.sayHi();
result += "OK";
rpcApi.sayHiWithParam("test");
result += "OK";
return result;
}
```
如果按照以上代码运行的话,调用客户端的test方法能够得到"OKOK"的响应,服务端的日志也说明请求能够正常地接收到。
但是如果客户端使用的`RpcApi`接口定义改为下面这样的话,会碰到问题:
```java
public interface RpcApi {
@ApiOperation(value = "", nickname = "sayHi")
void sayHi();
@ApiOperation(value = "", nickname = "sayHiWithParam")
void sayHi(String content); // 这里两个方法是同名的,只依靠@ApiOperation注解来区分的话会有问题
}
```
总的来说我们**建议用户在定义REST接口的时候保持每个接口方法的方法名在当前接口类中是唯一的**,如果您真的有无法规避的要求,必须将服务端接口定义为同名的话,可以考虑我上面给出的例子 : )
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services