Missing dependency for method

2019-09-09 19:51发布

问题:

I am running REST Web Service and after adding some new Web Services I got some errors. Why do I get these errors?

  SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK) at parameter at index 0
  SEVERE: Method, public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK), annotated with GET of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
  SEVERE: Missing dependency for method public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK) at parameter at index 0
  SEVERE: Method, public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK), annotated with DELETE of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.

I am using Jersey 1.1.1, these are my dependencies:

<dependencies>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
        <version>1.1.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>osgi_R4_core</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

回答1:

Looks like methods service.ProyectoHasPersonaRESTFacade.find() and service.ProyectoHasPersonaRESTFacade.remove() take one parameter which is not annotated (i.e. it means the methods expect the request entity to be passed into this parameter), however, these methods are mapped to HTTP GET and DELETE. Neither HTTP GET nor HTTP DELETE can have an entity. So the unannotated parameter on the corresponding Java methods does not make sense.

You can get the ID/PK of the object to be retrieved/deleted e.g. by putting it either in a path parameter or query parameter.



标签: rest jersey