首页 > 解决方案 > 如何在普通春季项目中将 swagger2 升级到 swagger3

问题描述

在我们的spring-webmvc项目中我们使用下面的代码来配置swagger2,现在我们想升级到swagger3,所以我们在pom文件中添加了springdoc-openapi-ui,我们需要在我们的swagger-configuration文件中进行哪些更改

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hjk.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(getApiInfo());
    }
    private ApiInfo getApiInfo() {
        return new ApiInfo(title, description, version, termsOfServiceUrl, contact, license, licenseUrl);
    }     
}

标签: spring-mvcswaggeropenapispringdoc-openapi-ui

解决方案


您必须像这样删除@EnableSwagger2 并更改您的Docket api()

@Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI().info(new Info().title("SpringShop API"));}

有关更多详细信息,请参阅此文档https://springdoc.org/#migrating-from-springfox


推荐阅读