SpringBoot -- Swagger2

Swagger2

  • SpringMvc配合Swagger2可以生成可读性和好的API文档
  • 在团队合作中这点尤为重要
  • Swagger2生成的为Restful API
  • Swagger2可以直接测试接口

在FeignServer的基础上进行集成

build.gradle中引入swagger2

build.gradle

 compile ('io.springfox:springfox-swagger2:'+swagger2Version)
    compile ('io.springfox:springfox-swagger-ui:'+swagger2Version)

创建swagger2配置类

Swagger2Config.java

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.bootcwenao.feignserver.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot Swagger2 test Restful API")
                .description("更多内容请详见代码")
                .termsOfServiceUrl("http://blog.csdn.net/cwenao")
                .contact("cwenao")
                .version("0.5.0")
                .build();
    }

}

controller上配置swagger2, httpMethod 如果不写会是所有的method

@Controller
public class FeignController {
    @Autowired
    FeignServer feignServer;

    @ApiOperation(value = "/testFeign",notes = "测试Feign",httpMethod = "GET")
    @ApiParam(name = "content",value = "参数:content")
    @RequestMapping("/testFeign")
    @ResponseBody
    public void testFeign(String content) {
        String ribbonStr = feignServer.testRealRibbon(content);
        System.out.println(ribbonStr);
    }
}

测试

如果只需指定的method,配置httpMethod


代码

代码请移步 Github参考地址

如有疑问请加公众号(K171),如果觉得对您有帮助请 github start
公众号_k171

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值