@FormDataParam 抛出严重:缺少依赖项

2022-01-21 00:00:00 rest java jersey

我正在使用 Jersey 上传文件.我定义了方法:

I am using Jersey to upload file. I defined the method:

@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Collection<Message> uploadImage(@FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) throws IOException {
}

并调用 Jersey 客户端的调用进行测试:

And invoke the call from Jersey Client for testing:

ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
String url = "http://localhost:8080/API/api/images/upload/150";
File f = new File("C:/Pictures/1360_435x300.jpg");
FormDataMultiPart form = new FormDataMultiPart();
form.bodyPart(new FileDataBodyPart("thumbnail", f));
String s = client.resource(url).type(MediaType.MULTIPART_FORM_DATA).accept(MediaType.APPLICATION_JSON).post(String.class, form);

但是,我得到:

严重:缺少公共 java.util.Collection 方法的依赖项ImageResource.uploadImage(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)在索引 1 处的参数处抛出 java.io.IOException

SEVERE: Missing dependency for method public java.util.Collection ImageResource.uploadImage(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 1

怎么了?

推荐答案

确保所有的库都是相同的版本(例如 1.13),并且不要忘记添加 mimepull.jar 和 jersey-multipart.jar.

Make sure all libs are the same version (e.g. 1.13), and don't forget to add mimepull.jar and jersey-multipart.jar as well.

相关文章