swagger2.9.2 和 springboot3.3.4版本冲突问腿

swagger2.9.2 和 springboot3.3.4版本冲突问腿

问题描述:当我们使用 swagger 2.9.2版本的时候,如果恰好我们使用的 springboot 版本是3.x版本,会出现启动报错的问题

解决办法:直接使用swagger 3.x 版本和 springboot 3.x 版本

解决步骤:

1.导入swagger3.x版本的maven依赖

在这里插入图片描述

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.2.0</version>
        </dependency>
2.在config包中加入swaager配置类

在这里插入图片描述

package com.example.demo.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
    
    
    @Bean
    public OpenAPI springShopOpenAPI() {
    
    
        return new OpenAPI()
                .info(new Info().title("标题")
                        .contact(new Contact())
                        .description("我的API文档")
                        .version("v1")
                        .license(new License().name("Apache 2.0").url("http://springdoc.org")))
                .externalDocs(new ExternalDocumentation()
                        .description("外部文档")
                        .url("https://springshop.wiki.github.org/docs"));
    }
}

3.启动项目访问swagger
http://localhost:8080/swagger-ui/index.html#/

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_61715584/article/details/142747551
今日推荐