Jersey REST WS Error: "There is no dependency for the method ... with parameter with index X"

I get the following error:

Apr 09, 2013 12:24:26 PM com.sun.jersey.spi.inject.Errors processErrorMessages SEVERE: The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.package.ImportService.specifyLocalFile(java.lang.String,java.lang.String,java.lang.String,java.lang.String) at parameter at index 0 SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.package.ImportService.specifyLocalFile(java.lang.String,java.lang.String,java.lang.String,java.lang.String) at parameter at index 1 SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.package.ImportService.specifyLocalFile(java.lang.String,java.lang.String,java.lang.String,java.lang.String) at parameter at index 2 SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.package.ImportService.specifyLocalFile(java.lang.String,java.lang.String,java.lang.String,java.lang.String) at parameter at index 3 SEVERE: Method, public javax.ws.rs.core.Response com.package.ImportService.specifyLocalFile(java.lang.String,java.lang.String,java.lang.String,java.lang.String), annotated with POST of resource, class com.package.ImportService, is not recognized as valid resource method. 

I have a previously working POST method that accepts Multipart data (file upload), and then some other String data fields from the form presented, here is the code:

 @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile( @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("param1") String param1, @FormDataParam("param2") String param2, @FormDataParam("param3") String param3) { .... .... return Response.status(200).entity(getEntity()).build(); } 

The error seems to be related to how form parameters are interpreted by Jersey. here's the code failure:

 @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/local") public Response specifyLocalFile( @FormDataParam("file") String fullFilePath, @FormDataParam("param1") String param1, @FormDataParam("param2") String param2, @FormDataParam("param3") String param3) { .... .... return Response.status(200).entity(getEntity()).build(); } 
+9
source share
3 answers

After a short search query, I will eventually consider some interesting cases, such as Failed to fix the problem with @FormParam or Missing mulipart JAR question dependency most aproximate message for my problem was the following: "There is no dependecy for the method" , to which I reply with a link to this POST, since I do not see the current solution for this particular one.

The problem appears to be with the @FormDataParam annotation when used with the @Consumes level @Consumes at the method level with the value MediaType.APPLICATION_FORM_URLENCODED .

When I changed the method signature to annotate each text field using @FormParam , the exception @FormParam . Check the fixed code below:

 @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/local") public Response specifyLocalFile() @FormParam("file") String fullFilePath, @FormParam("param1") String param1, @FormParam("param2") String param2, @FormParam("param3") String param3) { .... 

If the type of data received does not have to process MIME encodings, the @FormParam annotation will try to process the contents through serialization; in contrast, the @FormDataParam annotation requires some specific processing, which is configured when the @Consumes annotation has MediaType.MULTIPART_FORM_DATA . Hope this helps.

+11
source

I had the same error in my project.

1) you need to put all the jersey dependencies in the same version.

2) I also had a problem due to swagger @ApiParam anomalies:

 @ApiParam(value = "import file", required = true) @FormDataParam("file") InputStream inputStreamCsv 

Removing them did the trick:

 @FormDataParam("file") InputStream inputStreamCsv 

here is the link mentioning the problem: https://github.com/swagger-api/swagger-core/issues/1530

Finally, everything worked with this:

 @POST @Path("/import") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response import( @FormDataParam("file") InputStream inputStreamCsv, @FormDataParam("file") FormDataContentDisposition detailsFichier) {...} 
+3
source

For reference: in my case, it was a jersey-multipart dependency, used in a different version than in other Jersey libraries, causing this error due to multi-part data. → Be sure to use the same version number for all Jersey libraries! ( mvn dependency:tree your friend)

0
source

All Articles