Swagger3.0 与spring boot2.7x 整合避免swagger2.0与boot2.7冲突

注释掉2.0引入的俩包

直接引入3.0

  
            io.springfox
            springfox-boot-starter
            3.0.0
        

Swagger3.0 与spring boot2.7x 整合避免swagger2.0与boot2.7冲突_第1张图片

swagger配置文件粘贴即用哦


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //TODO 改为你项目使用的controller包目录
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    //构建api的详细信息方法
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("xx接口文档")
                //版本号
                .version("1.0")
                //描述
                .description("swagger3.0的为基础的文档哟")
                .build();
    }
}

最后配置文件改变mvc匹配规则即可

Swagger3.0 与spring boot2.7x 整合避免swagger2.0与boot2.7冲突_第2张图片

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

最后

swagger2.0访问地址是:

http://localhost:8080/swagger-ui.html
swagger3.0地址是:

http://localhost:8080/swagger-ui/index.html

你可能感兴趣的:(spring,boot,后端,java)