Why would “java.lang.IllegalStateException: The resource configuration is not modifiable in this context.” appear deploying Jersey app?

前端 未结 15 898
孤街浪徒
孤街浪徒 2020-11-30 15:06

I have created an app implementing REST services locally using:

Eclipse Indigo Jersey 2.4 Tomcat 7.0.47

When running locally using Eclipse, the services work

15条回答
  •  误落风尘
    2020-11-30 15:41

    Apparently the main causes of failure is because there is duplicate reference in the services path, this is multiple path ("/"), as well as the existence of resources without defined path or such resource classes do not count Less with some defined (@GET, @POST, @UPDATE, @DELETE, ...) method.

    In order to solve this, a path (not duplicated) must be indicated for each resource and at least in each resource there must be one or more published methods, the lack of these methods in different versions of jersey could cause this exception.

    Example:

    package com.contpaq.tech.service.resources;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Response;
    
    @Path("/")
    public class RootSrv {
    
      @GET
      @Produces(MediaType.TEXT_PLAIN + ";charset=utf-8")
      public Response getVersion() {
        return Response.ok().entity("NodeServer Versión 0.6.69").build();
      }
    }
    

提交回复
热议问题