欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

swagger 报错 Ambiguous handler methods mapped for ‘/v3/api-docs/‘

程序员文章站 2022-03-01 13:38:02
...

在启动项目A时, 调用/v3/api-docs 接口 发现报错 返回值

{"errorCode":"Unknown","code":500,"path":"/v3/api-docs/","stack":"","errorMsg":"Ambiguous handler methods mapped for '/v3/api-docs/': {public java.lang.String org.springdoc.api.OpenApiResource.openapiJson(javax.servlet.http.HttpServletRequest,java.lang.String) throws com.fasterxml.jackson.core.JsonProcessingException, public org.springframework.http.ResponseEntity springfox.documentation.oas.web.OpenApiControllerWebMvc.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)}"}

 

使用maven命令" mvn dependency:tree "排查, 发现是swagger的jar包冲突, 因为A依赖了B

项目A

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-core</artifactId>
            <version>1.1.49</version>
        </dependency>

项目B

            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-boot-starter</artifactId>
                <version>3.0.0</version>
            </dependency>

最终排除掉B项目中的依赖, 接口恢复正常

            <dependency>
                <groupId>com.xxx.xxx</groupId>
                <artifactId>project-B</artifactId>
                <version>1.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-boot-starter</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

另外有遇到提示报错

nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/type/JdbcType

导入jar包就正常了

<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.5</version>
</dependency>
相关标签: 给自己看的