<!-- swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.6</version> </dependency> <!-- 1.5.20以上版本ui不会有警告 --> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.24</version> </dependency>
/** * http://ip:port/doc.html * @author admin * @date 2021/7/6 */ @Configuration @EnableSwagger2 @EnableSwaggerBootstrapUI public class SwaggerConfiguration { @Bean public Docket createRestApi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("swagger-web-api") .version("1.0") .build(); } }
@RestController @RequestMapping("/api") @Api("api") public class DemoController { @PostMapping("/demo") @ApiOperation("demo") public void demo() { } }
请求:http://localhost:port/doc.html