在SpringBoot中使用Swagger

2017-04-28  本文已影响0人  RageYourDream_
  1. 首先需要导入Swagger依赖
    <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency>
    <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency>

  2. 在使用Swagger的Controller中使用注解@EnableSwagger2

  3. 定义Swagger的Bean

@Bean
public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.elong.Controller")) .paths(PathSelectors.ant("/api/*")) .build().apiInfo(apiInfo()); }

private ApiInfo apiInfo() { ApiInfo apiInfo = new ApiInfo( "Autops REST API", "Autops平台接口", "API TOS", "OPS", "xianghui.niu", "License of API", ""); return apiInfo; }

  1. 主要的注解使用方法
上一篇 下一篇

猜你喜欢

热点阅读