2

我有一个现有的 Spring 4 API 并已成功集成 springdoc-openapi 以在 JSON/YAML 中生成 OpenAPI 3 规范,并使用 springdoc-openapi 1.2.29 和 Spring Boot 15.2.2.RELEASE 显示 Swagger UI,但是似乎是在 springdoc-openapi 的更高版本中修复和增强的各种错误。不幸的是,如果我使用高于 springdoc-openapi 1.2.29 的版本,我会遇到与 Spring 4 的各种兼容性问题。

springdoc-openapi 和 Spring 4 是否有可用性兼容性矩阵?当我阅读 springdoc-openapi 文档时,我没有看到任何自述文件或发行说明表明存在 Spring 5 要求,但是如下所述,一旦您达到某个版本,就会在基础 springdoc-openapi 中使用 Spring 5 类。

我的相关POM:

    <!-- springdoc-openapi-ui -->
    <!-- anything over 1.2.33 uses Spring 5 MethodParameter.getParameter()-->
    <!-- anything over 1.2.29 uses Spring 5 org.springframework.http.codec.multipart.FilePart -->
    <!-- webjars-locator-jboss-vfs is required for running under JBOSS and exposing the swagger-ui -->
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.2.29</version>
    </dependency>
    <!--  
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-security</artifactId>
        <version>1.2.29</version>
    </dependency>
    -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>1.5.22.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>1.5.22.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator-jboss-vfs</artifactId>
        <version>0.1.0</version>
    </dependency>

当使用 springdoc-openapi-ui 1.2.30 时,它随后会引入 springdoc-openapi-common-1.2.30.jar,它会在尝试使用 org.springframework.http.codec.multipart.FilePart 时抛出异常。同样,使用 1.2.34 或更高版本将在 MethodParameter.getParameter() 上引发异常。

12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1) Caused by: java.lang.NoClassDefFoundError: org/springframework/http/codec/multipart/FilePart
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.GenericParameterBuilder.isFile(GenericParameterBuilder.java:271)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.GenericParameterBuilder.isFile(GenericParameterBuilder.java:296)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.AbstractRequestBuilder.buildParams(AbstractRequestBuilder.java:271)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.core.AbstractRequestBuilder.build(AbstractRequestBuilder.java:174)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.AbstractOpenApiResource.calculatePath(AbstractOpenApiResource.java:205)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.OpenApiResource.calculatePath(OpenApiResource.java:134)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.OpenApiResource.getPaths(OpenApiResource.java:99)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.AbstractOpenApiResource.getOpenApi(AbstractOpenApiResource.java:124)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springdoc.api.OpenApiResource.openapiJson(OpenApiResource.java:83)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:15:05,003 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at java.lang.reflect.Method.invoke(Method.java:498)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
12:15:05,004 ERROR [stderr] (ajp-localhost/127.0.0.1:8009-1)    ... 61 more

Spring 5 参考: https ://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/codec/multipart/FilePart.html

public interface FilePart
extends Part

Specialization of Part that represents an uploaded file received in a multipart request.

Since:
    5.0

有关如何解决此问题以在更高版本中利用 springdoc-openapi 中的错误修复和增强功能的任何建议?

4

1 回答 1

2

问题已确认并将作为 1.3.3 的一部分解决。请参阅下面的 Springdoc 记录的问题。感谢@bnasslahsen 的快速识别和纠正!

https://github.com/springdoc/springdoc-openapi/issues/563

于 2020-04-13T20:44:39.660 回答