@PathParam的Jersey错误

时间:2014-07-26 07:09:48

标签: java rest tomcat jersey

我正在使用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

有任何线索吗?

1 个答案:

答案 0 :(得分:0)

您应该使用@Path("{activityId}")代替@PathParam("{activityId}")

文档说明

@PathParam

  

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

@Path

  

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

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