Swagger2使用
程序员文章站
2022-07-02 21:47:27
...
1、pom.xml配置依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
2、Swagger配置类
@EnableSwagger2
@Configuration
public class Swagger {
Contact contact = new Contact("chen", "", "");
@Bean
public Docket docket(Environment environment){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.cf.swagger"))//扫描的包
.build();
}
public ApiInfo apiInfo(){
return new ApiInfo(
"chen的Swagger Api Documentation",
"Api Documentation",
"1.0", "urn:tos",
contact, "Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<VendorExtension>()
);
}
}
3、controller层写一个 hello 的api
@RestController
@Api(tags = "测试")
public class hello {
@GetMapping("/hello")
public String hello(){
return "hello";
}
}
4、网址:http://localhost:8080/swagger-ui.html
上一篇: Linux性能之CPU优化