不多说废话直接来:
-
pom.xml
<!-- 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>
-
swagger 配置类:
/** * Swagger生成api文档 */ @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("controller路径")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("") .description("") .termsOfServiceUrl("") .contact("") .version("1.0") .build(); } }
-
在controller 对应的接口上增加 swagger注解
@ApiOperation(value = "", notes="") 等等
-
启动项目,访问swagger地址:
localhost:8080/test/swagger-ui.html
-
springboot集成swagger结束