解决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内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论