赞
踩
(一)前提
我的springboot版本是3.2.2
(springboot版本大于3.0.0)使用swagger无需配置 添加swagger依赖即可使用
springboot版本在pom.xml里的parent标签中可以看到
同时springboot大于3.0.0版本要在application.properties配置
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
(二)遇到的问题
配置原本的依赖
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
这样输入网址localhost:8080/swagger-ui.html 网页会弹出窗口:
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
大致意思是Swagger无法自动推断API的基本URL要手动输入
输入http://localhost:8080/swagger-ui.html之后按确定没有反应,依然弹出此窗口 问题无法解决
并且idea返回信息提示依赖版本兼容冲突
(三)解决问题
更改依赖为
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-api</artifactId> <version>2.0.2</version> </dependency>
更改依赖后解决了问题 可以访问网页 输入网址自动变成Swagger UI
理由(我不确定):在Spring Boot 3.2.2版本中,springdoc-openapi-starter-webmvc-ui和springdoc-openapi-starter-webmvc-api是更适配的选择。因为springdoc项目是专门为OpenAPI 3.0规范设计的,而且与Spring Boot和Spring框架的最新版本保持较好的兼容性。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。