1,引入依赖
<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,建立配置
@Configuration
@EnableSwagger2
public class Swagger {
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.yangliwei.bootlaunch"))
.paths(PathSelectors.regex("/rest/.*"))
.build();
}
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("利用swagger2构建的API文档")
.description("用restful风格写接口")
.termsOfServiceUrl("")
.version("1.0")
.build();
}
}
3,具体接口写注释
![](https://i-blog.csdnimg.cn/blog_migrate/63e391f4460b791ea865ceece08fc879.png)