这是我上传文件的原因
@POST
@Path("/uploadFile")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Response uploadFileSuite(@HeaderParam("Access-Control-Allow-Origin")
@FormParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail,
@QueryParam("key") String key) {
//path = global variable
String uploadedFileLocation = PATH + fileDetail.getFileName();
// save it
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded to : " + uploadedFileLocation;
return Response.status(200).entity(output).build();
}
然而,当我尝试编译时,我不断收到以下错误:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response Project.MyResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String) at parameter at index 0
SEVERE: Missing dependency for method public javax.ws.rs.core.Response Project.MyResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String) at parameter at index 1
SEVERE: Missing dependency for method public javax.ws.rs.core.Response Project.MyResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String) at parameter at index 0
SEVERE: Missing dependency for method public javax.ws.rs.core.Response Project.MyResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response Project.MyResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String), annotated with POST of resource, class Project.MyResource, is not recognized as valid resource method.
我尝试了一切来修复它,但似乎没有任何效果。
非常感谢任何帮助。
这是我的pom.xml
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<version>1.9.31</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>lrfProject.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jersey-version>1.8</jersey-version>
</properties>
<repositories>
<repository>
<id>glassfish.java.net</id>
<name>GlassFish Maven Repository</name>
<url>http://download.java.net/maven/glassfish</url>
<layout>default</layout>
</repository>
<repository>
<id>m2.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
</repositories>
答案 0 :(得分:0)
看起来你在一个参数上有两个参数注释:
@HeaderParam("Access-Control-Allow-Origin")
@FormParam("file") InputStream uploadedInputStream,
应该是:
@HeaderParam("Access-Control-Allow-Origin") String origin,
@FormParam("file") InputStream uploadedInputStream,