【问题标题】:Swagger 3 and Java >= 9 JigsawSwagger 3 和 Java >= 9 拼图
【发布时间】:2021-02-03 01:34:48
【问题描述】:

我在基于 maven 的 Java11 应用程序上配置 Swagger 3 时遇到问题。

首先我在pom.xml中声明:

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>3.0.0</version>
    </dependency>

然后,我使用 Spring Beans 配置 Swagger:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket swaggerSpringMvcPlugin() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.***.***.controller.rest"))
            .paths(PathSelectors.any())
            .build()
            .apiInfo(metaData());
}

private ApiInfo metaData() {
    return new ApiInfoBuilder().title("***")
            .description("***")
            .contact(new Contact("**", "www.***.com", "**"))
            .license("Apache 2.0")
            .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
            .version("1.0.0")
            .build();
}

}

最后,我声明了module-info.java 要求:

    requires springfox.swagger2;
    requires springfox.spring.web;
    requires springfox.core;

当我尝试mvn clean install 时,我收到以下错误:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] error: the *** module reads package springfox.documentation.service from both springfox.core and springfox.spi
[ERROR] error: module springfox.spring.web reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module springfox.swagger2 reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module java.annotation reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.core reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module java.validation reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.beans reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.web reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.context reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module swagger.annotations reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.boot reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module springfox.core reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module springfox.spi reads package springfox.documentation.service from both springfox.core and springfox.spi
[ERROR] error: module spring.boot.autoconfigure reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] /private/tmp/***/src/main/java/module-info.java:[1] error: module *** reads package springfox.documentation.service from both springfox.core and springfox.spi
[INFO] 15 errors 
[INFO] -------------------------------------------------------------

我猜错了,但我找不到。谁能帮帮我?

【问题讨论】:

  • 在这里寻找问题 模块 A 从 X 和 Y 读取包 B

标签: spring-boot swagger java-11 java-9 springfox


【解决方案1】:

目前,没有官方解决方案可以解决此问题。 但是,使用 maven-shade-plugin 并将两个 springfox.core 和 springfox.spi jar 合并到一个包中是运行项目的最佳解决方法。

添加这个依赖提到这个 URL:https://jitpack.io/#valery1707/springfox-assembly

requires springfox.assembly;

而不是

 requires springfox.core;
 requires springfox.spi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    相关资源
    最近更新 更多