学习笔记:SpringMVC集成springfox-swagger2自动生成接口文档
SpringMVC集成springfox-swagger2自动生成接口文档
swagger配置步骤
1:添加maven的jar坐标
<!--swagger--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency>
2:添加配置 SwaggerConfig.java
package com.ibaiqi.spider.swagger; 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; /** * swagger相关配置 */ @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket produceApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } // Describe your apis private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("毕业设计") .description("毕业设计LOL助手app") .version("1.0-SNAPSHOT") .build(); } }
3:浏览显示: 工程路径后加swagger-ui.html
做产品的程序,才是好的程序员!