2016-09-14 46 views
4

我試圖使用multipart/form-data爲JAX-RS獲取文件上載。當我嘗試啓動服務器,它給了我這個錯誤:MULTIPART_FORM_DATA:找不到針對類型響應參數的注入源

[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response 
com.pododdle.resources.UploadResource.uploadAudio(int,int,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) 
    at index 2.;source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[text/html], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class 
com.pododdle.resources.UploadResource, handlerConstructors=[[email protected]]}, definitionMethod=public javax.ws.rs.core.Response 
com.pododdle.resources.UploadResource.uploadAudio(int,int,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition), parameters=[Parameter [type=int, source=auction_id, defaultValue=null], Parameter [type=int, source=category_id, defaultValue=null], Parameter [type=class java.io.InputStream, source=file, defaultValue=null], Parameter [type=class org.glassfish.jersey.media.multipart.FormDataContentDisposition, source=file, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}'] 

我的pom.xml看起來是這樣的:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.glassfish.jersey</groupId> 
      <artifactId>jersey-bom</artifactId> 
      <version>${jersey.version}</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 
    <dependency> 
     <groupId>org.glassfish.jersey.containers</groupId> 
     <artifactId>jersey-container-servlet-core</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.jersey.media</groupId> 
     <artifactId>jersey-media-multipart</artifactId> 
     <version>${jersey.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.jvnet.mimepull</groupId> 
     <artifactId>mimepull</artifactId> 
     <version>1.9.6</version> 
    </dependency> 

</dependencies> 
<properties> 
    <jersey.version>2.22.1</jersey.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

與球衣的2.22.1版本的運作mimepull的版本我從這裏得到:https://www.versioneye.com/java/org.glassfish.jersey.media:jersey-media-multipart/2.22.1

有什麼我缺少,或沒有正確配置?我這個新手,這樣下去容易對我... :)

+1

是否已在'ResourceConfig'類中註冊'MultipartFeature'?就像'register(MultipartFeature.class);'。 –

+0

嗨Cassio,我沒有resourceconfig類。我需要一個,它有什麼作用? –

+0

你可以有一個。但是你也可以在'web.xml'中註冊這個特性。 –

回答

4

一旦你沒有ResourceConfig,嘗試在web.xml部署描述符註冊MultiparFeature

<init-param> 
    <param-name>jersey.config.server.provider.classnames</param-name> 
    <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value> 
</init-param> 

如果您有更多的提供者類別名稱爲<param-value>,請使用,將它們分開。

相關問題