一导入依赖jar包
<!--swagger-api 依赖开始-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.2</version>
</dependency>
<!--swagger-api 依赖结束-->
yml配置文件 配置账号密码
swagger:
basic:
enable: true
username: admin
password: admin
swaggerConfig 配置
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//包名
.apis(RequestHandlerSelectors.basePackage("com.longzhong"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("序API接口")
.description("This is a restful api document of nader.")
.version("1.0")
.build();
}
}
访问地址
http://ip:端口/doc.html#/home
http://127.0.0.1:8080/doc.html#/home