【问题标题】:Error generating the API metadata for Cloud Endpoints classes in Eclipse在 Eclipse 中为 Cloud Endpoints 类生成 API 元数据时出错
【发布时间】:2015-02-11 01:30:35
【问题描述】:

我有两个不同的云端点方法,有两个不同的名称签名

@ApiMethod(name = "getWhiteCats", httpMethod = HttpMethod.POST)
 public CollectionResponse<Cat> getWhiteCats(CatCall request)

@ApiMethod(name = "getGrayCats", httpMethod = HttpMethod.POST)
public CollectionResponse<Cat> getGrayCats(CatCall request)

但是 Eclipse 给出了例外

描述资源位置路径类型生成时出现问题 您的 Cloud Endpoints 类的 API 元数据: com.google.api.server.spi.config.validation.DuplicateRestPathException: 具有相同休息路径的多个方法“POST collectionresponse_cat":"getWhiteCats" 和 "getGrayCats"

有什么想法可以解决这个问题吗?

【问题讨论】:

  • 我想看看有没有办法通过注解来指定返回值的名称,但是我没有看到。
  • 我通过为其中一种方法创建自己的包装类来解决它。

标签: java eclipse google-app-engine google-cloud-endpoints google-eclipse-plugin


【解决方案1】:

我通过在@apiMethod 注释中再传递一个参数解决了这个问题 例如你的情况

@ApiMethod(name = "getWhiteCats", path="Somepath_realted_to_your_service", httpMethod = HttpMethod.POST)

【讨论】:

    【解决方案2】:

    您需要使用 path = "yourPathHere" 为您的方法指定一个路径。 它应该看起来像这样:

    @ApiMethod(name = "getWhiteCats", path = "getWhiteCats", httpMethod = HttpMethod.POST)
     public CollectionResponse getWhiteCats(CatCall request)

    @ApiMethod(name = "getGrayCats", path = "getGrayCats", httpMethod = HttpMethod.POST)
    public CollectionResponse getGrayCats(CatCall request)
    

    路径不必是 @ApiMethod 的名称,但我强烈推荐它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2014-07-27
      相关资源
      最近更新 更多