SpringBoot 2.3 升级到 SpringBoot 2.7 爬坑-- Swagger 3

SpringBoot 2.3 升级到 SpringBoot 2.7 爬坑-- Swagger 报错 需要升级 到 3
详细见:https://www.cnblogs.com/vipsoft/p/18489922
SpringBoot 2.7 爬坑-- SpringDoc & Swagger (支持 SpringBoot 3.X)

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

image

添加yml配置

# Docs API配置
springdoc:
  swagger-ui:
    # API文档, 默认路径:swagger-ui/index.html, 通过http://localhost:8080/docs/index.html访问
    path: /docs/index.html
    # 开启Swagger UI界面
    enabled: true
    # 根据HTTP方法对API路径进行排序
    operations-sorter: method
  api-docs:
    # OpenAPI的路径描述,默认路径:/v3/api-docs, 通过http://localhost:8080/docs/api访问文档描述
    # OpenAPI描述定义默认为JSON格式, 通过http://localhost:8080/docs/api.yaml获取yaml格式
    path: /docs/api
    # 开启api-docs
    enabled: true
  # 配置需要生成接口文档的扫描包路径
  packages-to-scan: com.vipsoft.admin.controller
  # 配置需要生成接口文档的接口路径
  # paths-to-match:  /test/**,/user/**

修改 pom 引用

删除旧的 引用 swagger 2

<!-- swagger 2 -->
<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>
<!-- swagger 2 -->

<!-- 改为 -->

<!-- swagger 3 -->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>${springdoc.version}</version>
</dependency>
<!-- <dependency>-->
<!--     <groupId>org.springdoc</groupId>-->
<!--     <artifactId>springdoc-openapi-webmvc-core</artifactId>-->
<!--     <version>${springdoc.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!--     <groupId>io.swagger.core.v3</groupId>-->
<!--     <artifactId>swagger-annotations</artifactId>-->
<!--     <version>${swagger.core.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!--     <groupId>org.springdoc</groupId>-->
<!--     <artifactId>springdoc-openapi-webflux-ui</artifactId>-->
<!--     <version>${springdoc.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!--     <groupId>org.springdoc</groupId>-->
<!--     <artifactId>springdoc-openapi-security</artifactId>-->
<!--     <version>${springdoc.version}</version>-->
<!-- </dependency>-->
<!-- swagger 3 -->

Config 配置

SwaggerConfig 删除旧的配置

@Configuration
@EnableSwagger2
@Profile({"dev","test","local"})
public class SwaggerConfig {
 详细见:https://www.cnblogs.com/vipsoft/p/18489922
}

改为

@Configuration
public class OpenApiConfig {
详细见:https://www.cnblogs.com/vipsoft/p/18489922
}

posted @   VipSoft  阅读(118)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
历史上的今天:
2023-10-19 HanLP — 双数组字典树 (Double-array Trie) 实现原理 -- 代码 + 图文,看不懂你来打我
2022-10-19 Kubernetes(K8S) Deployment 升级和回滚
2022-10-19 Kubernetes(K8S) 拉取镜像 ImagePullBackOff pull access denied
2022-10-19 Kubernetes(K8S) Deployment 拉取阿里云镜像部署
2012-10-19 利用反射代替switch
2012-10-19 Excel合并行的数据
点击右上角即可分享
微信分享提示