2014-07-26 44 views
0

我使用的是新澤西州和我有以下兩種方法的RESTful:新澤西誤差@PathParam

@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 

任何線索?

回答

0

您應該使用的@Path("{activityId}")代替@PathParam("{activityId}")

文檔指出

@PathParam

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

@Path

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

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

+0

謝謝Keerthivasan! 我只是簡單的傻笑 –

+0

@ i_ch3ry不客氣:) – Keerthivasan