栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Knife4j使用教程

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Knife4j使用教程

Knife4j在springboot中的配置 详情了解请参考官方文档

knife4j是swagger的增强版,更契合微服务架构,ui前身是swagger-bootstrap-ui。

pom.xml导入依赖

        
            com.github.xiaoymin
            knife4j-spring-boot-starter
            
            
            2.0.9
        
config配置类
package com.xm.springbootdemos.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.spi.documentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket=new Docket(documentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        //.title("swagger-bootstrap-ui-demo RESTful APIs")
                        .description("# swagger-bootstrap-ui-demo RESTful APIs")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact("xx@qq.com")
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.xm.springbootdemos.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
Knife4j使用注解

api注解的使用方式和swagger一致。

Knife4j和swagger-bootstrap-ui的访问地址一致,都是 doc.html 。

今天也是元气满满的一天鸭!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/677513.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号