Springboot配置Swagger2登錄密碼的實現(xiàn)
Swagger
Swagger是使用OpenAPI規(guī)范(OAS)開發(fā)API的最廣泛使用的工具生態(tài)系統(tǒng)。Swagger由開源和專業(yè)工具組成,滿足幾乎所有的需求和用例。
一、配置Swagger
添加依賴
// web依賴 <dependency> ? ? ? ? <groupId>org.springframework.boot</groupId> ? ? ? ? <artifactId>spring-boot-starter-web</artifactId> </dependency> //swagger依賴 <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>
添加配置類
@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 = "基礎(chǔ)模塊")
@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
將接口文檔暴露在外網(wǎng)會出現(xiàn)一定的安全問題,此時我們需要給Swagger文檔配置登錄密碼。
二、配置Swagger登錄密碼
添加依賴
<dependency> ? ? <groupId>com.github.xiaoymin</groupId> ? ? <artifactId>swagger-bootstrap-ui</artifactId> ? ? <version>1.9.3</version> </dependency>
更新配置類
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI ?? ?//添加注解
public class SwaggerConfig {
}添加啟動類注解
@EnableSwagger2
配置yaml文件
swagger: ? basic: ? ? enable: true ?? ?// 啟用 ? ? username: 用戶名 ? ? password: 密碼
到此這篇關(guān)于Springboot配置Swagger2登錄密碼的實現(xiàn)的文章就介紹到這了,更多相關(guān)Springboot Swagger2登錄密碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot構(gòu)建Restful service完成Get和Post請求
這篇文章主要介紹了SpringBoot構(gòu)建Restful service完成Get和Post請求的示例代碼,感興趣的朋友一起看看吧2017-08-08
關(guān)于Spring源碼是如何解決Bean的循環(huán)依賴
這篇文章主要介紹了關(guān)于Spring源碼是如何解決Bean的循環(huán)依賴,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
Java數(shù)據(jù)庫連接池之proxool_動力節(jié)點Java學院整理
Proxool是一種Java數(shù)據(jù)庫連接池技術(shù)。方便易用,便于發(fā)現(xiàn)連接泄漏的情況2017-08-08

