SpringBoot整合Swagger
1.pom添加依赖。
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency>
v
2.添加swagger配置文件
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket swaggerSpringMavPlugin(){ // return new Docket(DocumentationType.SWAGGER_2) // .select() // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // .build() // ; return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() // 选择那些路径和api会生成document .paths(PathSelectors.any()) .build() ; } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Swagger接口") .description("API接口测试") .license("License Version 1.0") .version("1.0").build(); } }
3.添加注解
4.访问 swagger-ui.html
5.测试