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>
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