簡體   English   中英

執行文件上載休息Web服務時缺少方法依賴性

[英]Missing dependency for method when doing a file upload rest web service

我一直在努力了解如何解決此錯誤:

SEVERE: Missing dependency for method public java.lang.String com.myrest.FileService.uploadFile(java.io.File,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 0
SEVERE: Missing dependency for method public java.lang.String com.myrest.FileService.uploadFile(java.io.File,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 1
SEVERE: Method, public java.lang.String com.myrest.FileService.uploadFile(java.io.File,com.sun.jersey.core.header.FormDataContentDisposition), annotated with POST of resource, class com.myrest.FileService, is not recognized as valid resource method.

我正在使用基於Apache Jersey的休息Web服務並執行上傳服務。

以前有人遇到過這個錯誤嗎?

我收到此代碼的錯誤:

    @POST
    @Path("/upload{path:.*}")
    @Consumes("multipart/form-data")
    @Produces("text/plain")
    public String uploadFile(
            @FormDataParam("file") File file, 
            @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String fileLocation = "/files/" + fileDetail.getFileName();
        System.out.println("Copying file to : " + fileLocation);
        return "1";
    }

在我的情況下,問題是jersey-bundlecom.sun.jersey.contribs不同庫版本; 在settign之后,兩者都是相同的版本一切正常。

錯誤消息的最后一行讓我覺得你有一個丟失的JAR文件。

class com.myrest.FileService, is not recognized as valid resource method.

但除此之外我還沒有看到@FormDataParam被綁定到java.io.File之前,不確定框架是否可以將其反序列化為該對象。 您是否嘗試過反序列化為java.io.InputStream? 此外,如果您使用Maven進行構建,請檢查您的POM是否存在所有必需的依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM