pring-boot集成Springfox-Swagger2

简介:
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", "", "2570230521@qq.com"))
                .description("静态token=xxx")
                .version("2.0")
                .build();
    }
}
复制代码

 

复制代码
@ApiOperation(value="城市昨日数据总览+城市七天核心数据走势", notes="根据城市和日期展示数据")
@ApiImplicitParams({
        @ApiImplicitParam(name = "city", value = "城市名称", required = true, paramType = "query"),
        @ApiImplicitParam(name = "date", value = "日期", required = true, paramType = "query"),
        @ApiImplicitParam(name = "token", value = "静态token", required = true, paramType = "query")
})
@RequestMapping(value = "index", method = RequestMethod.GET)
复制代码

 

运行效果:访问 http://localhost:8081/sensors-data/swagger-ui.html

 










本文转自 小眼儿 博客园博客,原文链接:http://www.cnblogs.com/hujunzheng/p/6855824.html,如需转载请自行联系原作者
目录
相关文章
|
3天前
|
Java Maven
【SpringBoot专题_02】springboot集成Swagger详细教程
【SpringBoot专题_02】springboot集成Swagger详细教程
|
3天前
|
Java API
SpringBoot集成Swagger2组件
SpringBoot集成Swagger2组件
30 1
|
3天前
|
前端开发 搜索推荐 Java
springboot集成swagger knife4j 最详细的步骤 手把手教你继承swagger
springboot集成swagger knife4j 最详细的步骤 手把手教你继承swagger
292 0
springboot集成swagger knife4j 最详细的步骤 手把手教你继承swagger
|
3天前
|
JavaScript Java 测试技术
SpringBoot原理分析 | 开源框架:Swagger集成
SpringBoot原理分析 | 开源框架:Swagger集成
35 0
|
3天前
|
Java
SpringBoot集成swagger后出现: Failed to start bean ‘documentationPluginsBootstrapper‘的解决方法
SpringBoot集成swagger后出现: Failed to start bean ‘documentationPluginsBootstrapper‘的解决方法
53 0
|
6月前
|
Go API 微服务
Golang微服务框架Kratos轻松集成并使用Swagger UI
在我们的开发当中,调试接口,测试接口,提供接口文档给前端,那都是非常频繁的工作内容。 那么,我们需要用什么方法和工具来实施这些工作内容呢? Swagger,或者说OpenAPI。
132 0
|
7月前
|
Java API 网络架构
Spring Boot 学习研究笔记(六) -使用 Swagger 集成文档
Spring Boot 学习研究笔记(六) -使用 Swagger 集成文档
|
8月前
|
前端开发 Java API
springboot 集成swagger
springboot 集成swagger
80 0
|
9月前
|
资源调度 API
[Nestjs] 集成 Swagger
安装 Swagger 模块:首先,使用 npm 或者 yarn 安装 @nestjs/swagger 模块。

热门文章

最新文章