Can#39;t find @FormDataParam in Jersey 2.17(在 Jersey 2.17 中找不到 @FormDataParam)
问题描述
我对 Web 服务还很陌生,所以我从基本示例开始.这与文件上传有关.我正在为非 Maven 开发人员使用最新 (2.17) 版本的 Jersey 捆绑包.它指出:
I'm quite new to web services so I've started with basic examples. This one relates to file upload. I'm using latest (2.17) version of Jersey bundle for non-maven developers. It states that:
bundle 包含 JAX-RS 2.0 API jar、所有核心 Jersey 模块 jar 以及所有必需的第 3 方依赖项
bundle contains the JAX-RS 2.0 API jar, all the core Jersey module jars as well as all the required 3rd-party dependencies
.问题是我无法编译这部分:
. The problem is that I can not compile this part:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
String uploadedFileLocation = "d://uploaded/" + fileDetail.getFileName();
// save it
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded to : " + uploadedFileLocation;
return Response.status(200).entity(output).build();
}
似乎 @FormDataParam
在 Jersey 2.17 捆绑包中不存在,尽管文档说它存在.2.17 捆绑包不完整吗?我该如何解决这个问题?
It seems that @FormDataParam
doesn't exist in Jersey 2.17 bundle although docs says it does. Is the 2.17 bundle incomplete? How can I resolve this problem?
推荐答案
捆绑包仅包含核心模块(及其依赖项).不幸的是,Multipart 不是核心的一部分.您还需要 此依赖项 (Maven)
The bundle only includes the the core modules (and their dependencies). Unfortunately, Multipart is not part of the core. You'll need this dependency (Maven) also
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.17</version>
</dependency
如果您不使用 Maven,据我所知,这个工件只有一个其他依赖项(尚未包含在包中),它是 mimepull-1.9.3
.
If you're not using Maven, from what I can tell, this artifact only has one other dependency (that is not already included in the bundle), and it's mimepull-1.9.3
.
您可以在下面下载这两个工件
You can download both artifacts below
- jersey-media-multipart
- mimepull-1.9.3
这篇关于在 Jersey 2.17 中找不到 @FormDataParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Jersey 2.17 中找不到 @FormDataParam
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01