@Configuration public class Swagger2Config { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("cn.panyucable.springboot.controller")) .paths(PathSelectors.any()) .build(); }
private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("iToken API 文档") .description("iToken API 网关接口,http://www.zysheep.github.io") .termsOfServiceUrl("http://www.zysheep.github.io") .version("1.0.0") .build(); } }
4.1 启用 Swagger2
1 2 3 4 5 6 7
//Application` 中加上注解 `@EnableSwagger2` 表示开启 `Swagger @EnableSwagger2 public class ServiceAdminApplication { public static void main(String[] args) { SpringApplication.run(ServiceAdminApplication.class, args); } }