【问题标题】:Jersey error with @PathParam@PathParam 的泽西岛错误
【发布时间】:2014-07-26 07:09:48
【问题描述】:

我正在使用 Jersey,我有以下两种 RESTful 方法:

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public List<Activity> getAllActivities() {
    return activityRepository.findAllActivities();
}

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@PathParam("{activityId}")
public Activity getActivity(@PathParam("activityId") String activityId) {
    return activityRepository.findActivity(activityId);
}

在我添加第二种方法之前,一切都运行良好。但是,我的 tomcat 现在出现以下错误。

org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
[[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by @Consumes and @Produces annotations

有什么线索吗?

【问题讨论】:

    标签: java rest tomcat jersey


    【解决方案1】:

    您应该使用@Path("{activityId}") 而不是@PathParam("{activityId}")

    文档指出

    @PathParam

    将 URI 模板参数的值或包含模板参数的路径段绑定到资源方法参数、资源类字段或资源类 bean 属性。

    @路径

    标识资源类或类方法将为请求提供服务的 URI 路径。

    因此,@Path 应该用于定义资源方法将服务的 URI 路径。

    【讨论】:

      猜你喜欢
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 2011-08-02
      相关资源
      最近更新 更多