簡體   English   中英

@PathParam的球衣錯誤

[英]Jersey error with @PathParam

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

有什么線索嗎?

您應該使用@Path("{activityId}")而不是@PathParam("{activityId}")

文檔指出

@PathParam

將URI模板參數的值或包含模板參數的路徑段綁定到資源方法參數,資源類字段或資源類bean屬性。

@路徑

標識資源類或類方法將為其服務的URI路徑。

因此, @Path應該被用來定義URI路徑資源的方法將服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM