spring cloud feign swagger2 搭建

1.pom 引用

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>

spring cloud  feign swagger2 搭建

 

 

2 .创建配置类

SwaggerConfig
/**
* @ClassName: swagger2配置
* @Description: TODO
* @date 2021.03.12
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.servicefeign.controller"))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("园区api接口")
.description("--------------------------------")
.version("1.0")
.build();
}

}

3.api 添加注解
RestController
@Api
public class HelloFeignController {


@Autowired
private HelloFeignService helloFeignService;
@GetMapping(value = "hi")
@ApiOperation(value = "根据Name获取测试", notes = "测试列表")
@ApiImplicitParam(name = "name", value = "名称", paramType = "query", required = true, dataType= "String")
public String sayHi(@RequestParam String name){
return helloFeignService.sayHiFromClientOne(name);
}

}

运行 ip:端口/swagger-ui.html

spring cloud  feign swagger2 搭建

 

上一篇:整合Swagger2文档API 和 整合log4j打印日志


下一篇:最新版Swagger 3升级指南和新功能体验!