解决:java.lang.NoSuchMethodError: 'boolean io.swagger.v3.oas.models.media.Schema.getExampleSetFlag('
一·问题描述:
1.Springboot(3.1.6版本) 整合 springdoc-openapi-starter-webmvc-ui(2.1.0版本)时,启动服务不报错,访问http://127.0.0.1:8089/swagger-ui/index.html时报该异常,500异常
2.异常堆栈如下图所示:
3.配置如下图所示:
二·异常原因:
1.项目maven依赖里面,存在多种swagger版本依赖,导致版本冲突
2.项目里面除了springdoc-openapi-starter-webmvc-ui依赖外,不应该存在任何其他swagger依赖,该springdoc-openapi依赖会自动引入所有相关依赖
<!-- Swagger 依赖 -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
三·解决办法:
1.打开maven的依赖分析界面
2.在依赖分析界面搜索swagger,分析是否存在多个来源
3.排除掉多余的swagger依赖来源
四·测试结果:可以成功访问swagger-ui界面
http://127.0.0.1:8089/swagger-ui/index.html