import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket restApiForSensors() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("sensors data") .forCodeGeneration(true) .select() // .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .paths(PathSelectors.ant("/api/sensors/data/**")) .build() .useDefaultResponseMessages(false); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("倍全SpringBoot Swagger2 RESTful API") .contact(new Contact("hjzgg", "", "[email protected]")) .description("静态token=xxx") .version("2.0") .build(); } }
运行效果:
参考资料:
spring-boot集成Springfox-Swagger2
时间: 2024-10-15 08:32:46