Search code examples
javajerseyjax-rs

What am I doing wrong in this jersey Java class?


Here is the class :-

 package com.bablo.rest;

 import javax.websocket.server.PathParam;
 import javax.ws.rs.Path;

 @Path("/")
 public class Library {
   @Produces("text/plain") 
   @Path("/books/{name}")
   public String getBook(@PathParam("name") String name){
     System.out.println(name);
      return "My Name is Anthony Goncalves";
  }
}

Its giving this as error

A sub-resource locator, public java.lang.String com.bablo.rest.Library.geBook(java.lang.String), can not have an entity parameter. Try to move the parameter to the corresponding resource method.

and

Missing dependency for method public java.lang.String com.bablo.rest.Library.getBook(java.lang.String) at parameter at index 0

I am invoking this webservice through the Browser like this

     http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo

Also I am doing curl:

     curl -X GET http://localhost:8080/JAXRS-HelloWorld/rest/books/bablo

Solution

  • I believe you meant to use

    javax.ws.rs.PathParam
    

    rather than

    javax.websocket.server.PathParam