最新下载
热门教程
- 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: 密码
相关文章
- 百炼英雄怎么挂机 挂机方式及各等级最优点位攻略 12-15
- 百炼英雄vip礼包码大全 最新可用vip礼包码 12-15
- 光与影33号远征队符文收集:强力复生符文效果及获取方式详解 12-15
- 百炼英雄兑换码有哪些 最新可用兑换码及兑换方式 12-15
- 神器传说怎么克制闪避流 闪避流克制阵容实战攻略 12-15
- 神器传说怎么打异兽分最高 异兽冲榜高分搭配 12-15