第一步:添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
第二步:配置SwaggerConfig文件
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.shuaishen.controller"))
.paths(PathSelectors.any())
.build().apiInfo(new ApiInfoBuilder().title("图书管理系统").version("v1.0").build());
}
}
第三步:启动项目,浏览器输入http://localhost:8001/swagger-ui.html
注意:浏览器输入的端口号要与启动成功的后端服务器端口保持一致,否则会出现
localhost 拒绝了我们的连接请求