Springboot2.7.5整合knife4j3.0.3

可以尝试使用下面的配置文件解决

Springboot2.7.5整合knife4j3.0.3_第1张图片

Springboot2.7.5整合knife4j3.0.3_第2张图片
运行效果
Springboot2.7.5整合knife4j3.0.3_第3张图片

下面是代码

application.yml

spring:
  profiles:
    active: dev
  application:
    name: auth
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
#      spring2.6及其以上版本需要设置

Knife4jConfig

package ltd.oyqf.system.config;

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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Knife4jConfig {
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        String groupName="3.X版本";
        Docket docket=new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("这是knife4j API ")
                        .description("# 这里记录服务端所有的接口的入参,出参等等信息")
                        .termsOfServiceUrl("http://blog.oyqf.ltd")
                        .contact(new Contact("sky","http://blog.oyqf.ltd","[email protected]"))
                        .version("3.0")
                        .build())
                //分组名称
                .groupName(groupName)
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("ltd.oyqf.system.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    private ApiInfo adminApiInfo() {

        //网页的相关属性
        return new ApiInfoBuilder()
                .title("后台管理系统-API文档")
                .description("本文档描述了后台管理系统微服务接口定义")
                .version("1.0")
                .contact(new Contact("sky", "http://blog.oyqf.ltd", "[email protected]"))
                .build();
    }
}

补充更新:接口文档注释
Springboot2.7.5整合knife4j3.0.3_第4张图片

你可能感兴趣的:(springboot,spring,boot)