当前位置:网站首页>knife4j配置使用直接拷贝即可

knife4j配置使用直接拷贝即可

2022-06-10 19:21:00 贺贺学编程

废话我就不多说了,直接上maven依赖

<!-- knife4j接口文档 -->
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>3.0.3</version>
</dependency>

然后写一个配置类Knife4jConfig,为了避免导错包,把包也给你们了

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.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() {
    
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("xxx接口说明")
                        .description("xxx接口描述")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("xxx公司", "http://xxx.com/", "[email protected]"))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

运行项目访问 http://localhost:8080/doc.html

原网站

版权声明
本文为[贺贺学编程]所创,转载请带上原文链接,感谢
https://hezhiying.blog.csdn.net/article/details/125209912