最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Springboot配置Swagger2登录密码实现代码
时间:2022-06-29 01:53:05 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Springboot配置Swagger2登录密码实现代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
Swagger
Swagger是使用OpenAPI规范(OAS)开发API的最广泛使用的工具生态系统。Swagger由开源和专业工具组成,满足几乎所有的需求和用例。
一、配置Swagger
添加依赖
// web依赖//swagger依赖 org.springframework.boot spring-boot-starter-web io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2
添加配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi()
{
return new Docket(DocumentationType.SWAGGER_2)
.groupName("")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("包名"))
.paths(PathSelectors.any())
.build();
}
public ApiInfo apiInfo()
{
return new ApiInfoBuilder()
.title("接口")
.description("接口说明")
.version("1.0")
.build();
}
}
使用
// 控制层
@Api(tags = "基础模块")
@RestController
@RequestMapping("/base")
public class BaseController {
@ApiOperation(value = "查询")
@RequestMapping(value = "/findList", method = RequestMethod.POST)
public RestResponse findList(@RequestBody Param param)
{
return RestResponse.ok();
}
}
访问地址
localhost:8080/swagger-ui.html
将接口文档暴露在外网会出现一定的安全问题,此时我们需要给Swagger文档配置登录密码。
二、配置Swagger登录密码
添加依赖
com.github.xiaoymin swagger-bootstrap-ui 1.9.3
更新配置类
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI //添加注解
public class SwaggerConfig {
}
添加启动类注解
@EnableSwagger2
配置yaml文件
swagger:
basic:
enable: true // 启用
username: 用户名
password: 密码
相关文章
- 豚豚剧App官方入口下载:海量影视资源一键解锁 02-04
- 漫蛙漫画网APP最新版本下载-漫蛙正版漫画资源免费安装入口 02-04
- picacg2.1.2.3.4最新版-picacg安装包高速下载 02-04
- 百度网盘网页版入口-百度网盘网页端登录平台 02-04
- 漫蛙漫画网页最新下载入口-漫蛙漫画APP安卓苹果安装包下载 02-04
- 腾讯视频24小时人工客服热线详情-腾讯视频官方人工客服地址 02-04