我正在尝试使用multipart / form-data为JAX-RS上传文件。当我尝试启动服务器时,它给了我这个错误:
[[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=[org.glassfish.jersey.server.model.HandlerConstructor@29d4c93f]}, 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
我缺少什么,或者配置不正确?我是新手,所以对我很轻松...... :)
答案 0 :(得分: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>
中有更多提供者类名称,请使用,
将它们分开。