Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure Swagger2 login password for Springboot

Shulou Source: shulou.com Published: 2022-06-01 06:10:46 10月14日 Update

This article introduces the knowledge of "how to configure Swagger2 login password for Springboot". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Swagger

Swagger is the most widely used tool ecosystem for developing API using the OpenAPI specification (OAS). Swagger consists of open source and professional tools that meet almost all needs and use cases.

1. Configure Swagger

Add dependency

/ / web depends on org.springframework.boot spring-boot-starter-web//swagger depends on io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2

Add configuration class

@ Configuration@EnableSwagger2public class SwaggerConfig {@ Bean public Docket createRestApi () {return new Docket (DocumentationType.SWAGGER_2) .groupName (") .apiInfo (apiInfo ()) .select () .ap is (RequestHandlerSelectors.basePackage (" package name ") .build () } public ApiInfo apiInfo () {return new ApiInfoBuilder () .title ("interface") .description ("interface description") .version ("1.0") .build ();}}

Use

/ / Control layer @ Api (tags = "basic module") @ RestController@RequestMapping ("/ base") public class BaseController {@ ApiOperation (value = "query") @ RequestMapping (value = "/ findList", method = RequestMethod.POST) public RestResponse findList (@ RequestBody Param param) {return RestResponse.ok ();}}

Access address

Localhost:8080/swagger-ui.html

Exposing the interface document to the public network will cause some security problems. At this time, we need to configure the login password for the Swagger document.

Configure Swagger login password

Add dependency

Com.github.xiaoymin swagger-bootstrap-ui 1.9.3

Update configuration class

@ Configuration@EnableSwagger2@EnableSwaggerBootstrapUI / / add comment public class SwaggerConfig {}

Add startup class comments

@ EnableSwagger2

Configure the yaml file

Swagger: basic: enable: true / / enable username: username password: password "how to configure Swagger2 login password for Springboot". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Configuration password login interface content tools documents more comments knowledge practical security learning next professional dilemma address basic actual situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Linux vpn Xiaomi