我收到以下错误:
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.
我有一个以前工作的 POST 方法,它需要一个多部分数据(文件上传),然后是提交表单中的一些其他字符串数据字段,代码如下:
@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();
}
该错误似乎与 Jersey 解释表单参数的方式有关。这是失败的代码:
@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();
}