【问题标题】:Integration error jersey-multipart and swagger集成错误球衣 - 多部分和招摇
【发布时间】:2014-05-06 07:58:57
【问题描述】:

我有一个使用 Jersey-1 的 JAX-RS 网络服务。目前只有一种方法可以发送带有附件的邮件。附件必须作为多部分表单数据提供。

@POST
@Path("/mail")
@Consumes(MediaType.MULTIPART_FORM_DATA)   
public Response sendInfomailWithAttachment(

        @Context ServletContext context,
        @Context SecurityContext security,

        @QueryParam ("FROM") String senderAddress,
        @QueryParam ("SUBJECT") String subject,

        @QueryParam ("TO") String toRecipients,
        @QueryParam ("CC") String ccRecipients,
        @QueryParam ("BCC") String bccRecipients,

        @QueryParam ("noCopy") boolean sendNoCopy,

        @FormDataParam("attachment") InputStream fileInputStream,
        @FormDataParam("attachment") FormDataContentDisposition contentDispositionHeader,
        @FormDataParam("attachment") FormDataBodyPart fileBody,

        @FormDataParam("content") FormDataBodyPart content
        ){}

该方法效果很好。但是当我尝试集成 swagger 时,我总是会收到这个错误:

严重:缺少公共 javax.ws.rs.core.Response 方法的依赖项...在索引 8 处的参数处引发 java.lang.Exception (参数 9、10 和 11 也会抛出此错误)

结合

严重:方法,公共 javax.ws.rs.core.Response ... 抛出 java.lang.Exception,用资源 POST 注释,类 com.mywebservice.MyClass,不被识别为有效的资源方法。

如果我扔掉 FormDataParam 的东西,服务会正常启动,也可以使用 swagger 集成。

我用

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.3</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.17</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.17</version>
    </dependency>

<dependency>
        <groupId>com.wordnik</groupId>
        <artifactId>swagger-jersey-jaxrs_2.10</artifactId>
        <version>1.3.4</version>
    </dependency>

是否有任何已知的干扰?我还能做些什么来解决这个问题?

【问题讨论】:

    标签: java web-services jax-rs swagger


    【解决方案1】:

    我发现,这是一个 Maven 解析问题。

    swagger lib 1.3.4 使用 jersey-core-1.3 和 jersey-server-1.3,已被 maven 选用。相反,我在 1.17 中需要它,比如 jersey-servlet 和 jersey-multipart 版本。所以我不得不将这两个依赖项添加到 pom 中,以使 maven 依赖项解析使用 1.17 而不是 1.13。

    【讨论】:

    • 嗨@tareq,我将 jersey-servlet 和 jersey-multipart 都更新到了 1.18.1,但我仍然面临同样的问题
    • @agpt 您应该检查项目中已解决的依赖项。如果我没记错的话,我需要同一版本中的所有球衣依赖项。我想我在 1.17 中都拥有了它们,现在我更新到 jersey-2 并在 2.5.1 中全部使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多