spring boot 多模块项目搭建Knife4j文档,swagger-ui x2

介绍:  knife4j   jeecg-boot用的就是这个,我之前要搭过swagger-ui,但外观,体验都没有knife4j好,我没记错的话已经停止发布版本了,所以我的多模块项目就用到了这个,还搭建了jwt  token获取我也是在网上找的工具。

package com.zuodou.knife4jconfig;

import com.google.common.base.Optional;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import com.zuodou.enums.CommonConstant;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;

@Configuration
@EnableSwagger2
public class Knife4jConfiguration {
    // 定义分隔符,配置Swagger多包
    private static final String splitor = ";";
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定Controller扫描包路径  这种是指定扫描多个不同的包,没研究好,出现了问题,我就把包名统一改成com.zuodou
//                .apis(basePackage("zuodou.zuodousystem"+splitor+"zuodou.zuodoubase"))
                .apis(basePackage("com.zuodou"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
    // api基本信息
    private ApiInfo apiInfo() {
        return new ApiInfo("dxiaodang's swagger",
                "测试knife4j-ui",
                "v1.0",
                "http://mail.qq.com",
                new Contact("dangbo", "http://mail.qq.com", "[email protected]"),  //作者信息
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}

项目结构展示

spring boot 多模块项目搭建Knife4j文档,swagger-ui x2_第1张图片

其他的没什么,那个注入过去就差不多,依赖你用的什么spring boot 版本就得去找对应的knife4j匹配的版本,或者你手动去输一个一个试

spring boot 多模块项目搭建Knife4j文档,swagger-ui x2_第2张图片

 

 

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