1. 添加依赖
io.springfoxspringfox-swagger22.7.0io.springfoxspringfox-swagger-ui2.7.0
2. 添加配置类
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;/*** @author zhangh * @version V1.0.0* @projectName parent* @title SwaggerConfig * @package com.gdd.videos.common * @date 2019/9/3 9:44 * @explain swagger2的配置内容仅仅就是需要创建一个Docket实例*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {// 创建一个Docket实例@Beanpublic Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).pathMapping("/").apiInfo(apiInfo()).select()// controller接口路径.apis(RequestHandlerSelectors.basePackage("com.gdd.videos.mini_api.controller")).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("springboordemo").description("Springboot整合Demo").version("0.0.1").build(); // 这部分信息其实可以自定义到配置文件中读取}}
3. 常用注解:
附上链接: https://blog.csdn.net/ajklaclk/article/details/80736042
4. 启动后访问路径
http://localhost:8080/swagger-ui.html
注意:
如果是多模块配置,还需在项目入口文件中加上要扫描的包基本路径:
如图:
谢谢!