A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by“@Consumes” and “@Produces” annotations

后端 未结 4 1379
北荒
北荒 2021-01-17 17:37

How can the following produce this error when they have different URLs ?

@Path(\"/job/{empId}/empProfile\")
public EmpProfileResource delegateToEventProfileR         


        
相关标签:
4条回答
  • 2021-01-17 18:08

    This error arises if we have written @PathParam instead of @Path in our service class or where ever we are defining the path for same.

    0 讨论(0)
  • 2021-01-17 18:10

    Remove the @Path("/") from the sub-resource classes. Sub-resource classes don't need them. And if they have them, they get added as root resource classes, if you are scanning for @Path annotated classes. And this is the problem. You haven't show the methods of the sub-resource classes, but because the have the same root path, I would imagine that the problem is caused by some overlapping methods. So just remove the @Path("/") on sub-resource classes, and you should be OK.

    0 讨论(0)
  • 2021-01-17 18:11

    I had the same error. Most people resolved the error by changing their @Path annotations because they where ubiquitous. In my case something different happened. I modified a package from aaa to bbb for example. For some reason in the artifact deployed to the server there where both the aaa and bbb packages, so the resources where duplicated and the server raised the exception. I had to clear the previous deployed artifact and deploy the new. Someone may check this case also where the error appears. Of course at the end of the day the reason is again a path ubiquity. I am suffering with the same problem i have also updated a version check but its give me a same problem may jersey frame works is not supporting this

    0 讨论(0)
  • 2021-01-17 18:28

    I had this error two times now. Both were different:

    First time I had at the following above GET and POST Methods etc.

    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    

    But I didn't have it infront of the class. So if you have different class-ressources like:

    @Path("/users") 
    public Class User{}
    

    and

    @Path("/lists")
    public Class List{}
    

    Then BOTH of them need the

    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    

    infront of them:

    @Path("/users")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON}) 
    public Class User{}
    

    Second time I moved a resource (endpoint) class from one folder to a different one (via refactor from Intellij) and apparently the IDE doesn't recognize this. Then the exact problem occurs which Panagiotis Piperopoulos already described.

    To fix it I did the following: Go to the folder where you project is located (<working_directory>). There you will find a folder called target (<working_directory>\target)

    There was in my case 1: a war file. Delete that.

    2: A folder which contains the meta-inf and web-inf and index.html. The name is probably your module name (in IntelliJ: File -> Project Structure -> Module). Rename that folder to something like <old_name>_old

    If you re-compile your code then the folder and a new .war file should appear.

    0 讨论(0)
提交回复
热议问题