当前位置: 代码网 > it编程>编程语言>Java > Spring Boot 3.x 整合Swagger的示例教程

Spring Boot 3.x 整合Swagger的示例教程

2025年06月17日 Java 我要评论
解决springfox 依赖注入失败问题:org.springframework.beans.factory.unsatisfieddependencyexception: error creatin

解决springfox 依赖注入失败问题:

org.springframework.beans.factory.unsatisfieddependencyexception: 
error creating bean with name 'apidocumentationscanner' defined in url ···

最佳方案是放弃 springfox 2.x,改用 springdoc openapi,因为:

  • springfox 2.x 已停止维护

  • springfox 3.x 对 spring boot 支持有限

  • springdoc 是当前最活跃的 spring api 文档项目

第一步:添加依赖:

<dependency>
            <groupid>org.springdoc</groupid>
            <artifactid>springdoc-openapi-starter-webmvc-ui</artifactid>
            <version>2.5.0</version>
        </dependency>

第二步:添加配置:

@configuration
public class swaggerconfig {
    @bean
    public openapi springshopopenapi() {
        return new openapi()
                .info(new info()
.title("spring boot 中使用 swagger ui 构建 restful api")
                        .contact(new contact())
                        .description("sun提供的 restful api")
                        .version("v1.0.0")
                        .license(new license().name("apache 2.0")
.url("http://springdoc.org")))
                .externaldocs(new externaldocumentation()
                        .description("外部文档")
                        .url("https://springshop.wiki.github.org/docs"));
    }
}

 application.properties配置:

springdoc.api-docs.path=/v3/api-docs
springdoc.api-docs.enabled=true
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.enabled=true

第三步:访问:

http://localhost:8080/swagger-ui.html

到此这篇关于spring boot 3.x 整合swagger教程的文章就介绍到这了,更多相关spring boot 3.x 整合swagger内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com