Home > database >  Spring Boot2 series
Spring Boot2 series

Time:10-08

Spring Boot2 series (17) SpringBoot integration Swagg

4 minutes

After the separation, before and after maintenance interface documentation is an essential work, basically

Is the state of an ideal design, interface document shall be issued to the front-end and back-end, everyone according to the established rules of their development, to develop good docking can online, of course this is a very good state, rarely met in actual development situation, the interface is always in constant change, change to maintenance, friends all know that I have done this thing how big! Well, there are some tools can help to reduce our workload, Swagger2 is one of them, as for the other similar functions but charge of software, introduced here is not to do too much, in this paper, we talk to us in the Spring under the Boot of how to integrate Swagger2,

Engineering to create

The first, of course, is to create a Spring Boot program, to join the web rely on, to create success, to join two Swagger2 related dependence, complete dependence is as follows:

IO. Springfox Springfox - swagger2 & lt;/artifactId> 2.9.2 & lt;/version> IO. Springfox Springfox swagger - ui 2.9.2 & lt;/version> Org. Springframework. Boot Spring - the boot - starter - web
Swagger2 configuration

Swagger2 configuration is also relatively easy after the project to create success, only need a Docket beans can be supplied by the developers themselves, are as follows:

@ Configuration @ EnableSwagger2 public class SwaggerConfig {@ Bean public Docket createRestApi () {return new Docket (DocumentationType. SWAGGER_2). PathMapping ("/"). The select () apis (RequestHandlerSelectors. BasePackage (org. Javaboy. "controller")). The paths (PathSelectors. Any ()). The build () apiInfo (new ApiInfoBuilder (.) the title (" Swagger SpringBoot integration "). The description (" SpringBoot Swagger, detailed information... "). The version (" 9.0 "). Contact (new contact (" agghh ", "blog.csdn.net", "[email protected]")). The license (" The Apache license "). The licenseUrl (" http://www.javaboy.org "). The build ()); }}
Here to provide a configuration class, first by @ EnableSwagger2 annotations enable Swagger2, then configure a Docket Bean, this Bean, configure the mapping path and to scan the location of the interface, in apiInfo, main configuration Swagger2 document web site information, for example, the site title, a description of the site, contact information, the protocol used, etc.,

So, Swagger2 if configuration is successful, very convenient,

Start the project at this time, enter http://localhost:8080/swagger-ui.html, can see the following page, that have been configured for success:

  • Related