2012-06-24 72 views
2

我正在開發中,我使用一個ID在URL中指定一個病人,這樣的REST Web服務:PathParam與新澤西州的REST

WS/services/patient/1

其中「1」是病人的ID。因此,在代碼中,我指定這樣的:

@GET 
@Path("{id}") 
public void getPatient(@PathParam("id") int cId) { 
... 
} 

我看到它在一個例子,但我失敗了。我得到這個錯誤:

com.sun.jersey.api.container.ContainerException: Method, public void PresentationLayer.PatientResource.getPatient(int), annotated with GET of resource, class PresentationLayer.PatientResource, is not recognized as valid Java method annotated with @HttpMethod.

我不知道爲什麼這樣做。在這個例子中,我看到它的工作。任何提示?

編輯:如果我不寫@PathParams(「id」),它的工作原理...但是,那麼,我怎麼能從網址獲得id?

+0

作爲一個猜測:你需要返回一些內容,但你的返回類型是* void *。 –

+0

將日誌級別調高爲DEBUG或ALL。在這種情況下,當解決配置問題時,您需要能夠準確地看到底下發生了什麼。隨時瞭解更多有關該問題的內容,隨時進一步編輯您的問題以包含更多詳細信息。就目前而言,我不確定這是否可以支付,但這是一個好的開始,並且提供更多的細節可能是一個很好的問題。祝你好運! – jmort253

+0

爲什麼我需要返回任何東西?如果我不在參數網站中編寫@PathParams,它可以很好地工作(但是我不能從url中獲得id ...) – Frion3L

回答

8

com.sun.jersey.api.container.ContainerException: Method, public void PresentationLayer.PatientResource.getPatient(int), annotated with GET of resource, class PresentationLayer.PatientResource, is not recognized as valid Java method annotated with @HttpMethod.

您嘗試使用服務不返回響應(返回類型void)的方法的GET請求。