1.pom.xml introduction of Swagger 2.7 jar package
<!--Swagger2 Rest API start - <Dependency> <groupId>Io.springfox</groupId> <Artifactid>Springfox-swagger2</Artifactid> <version>2.7.0</version> </Dependency> <Dependency> <groupId>Io.springfox</groupId> <Artifactid>Springfox-swagger-ui</Artifactid> <version>2.7.0</version> </Dependency> <!--Swagger2 Rest API End -
2.swaggerconfig.class (placed in a place that can be scanned by spring)
Importorg.springframework.boot.context.properties.ConfigurationProperties;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;ImportSpringfox.documentation.builders.ApiInfoBuilder;Importspringfox.documentation.builders.PathSelectors;Importspringfox.documentation.builders.RequestHandlerSelectors;ImportSpringfox.documentation.service.ApiInfo;Importspringfox.documentation.service.Contact;ImportSpringfox.documentation.spi.DocumentationType;ImportSpringfox.documentation.spring.web.plugins.Docket;ImportSpringfox.documentation.swagger2.annotations.EnableSwagger2;/** * @authorTangzedong * @apiNote swagger2 configuration file *@since2018/9/4 10:46*/@Configuration @enableswagger2@configurationproperties Public classSwaggerconfig {@Bean PublicDocket API () {return NewDocket (documentationtype.swagger_2). Forcodegeneration (true)
. GroupName ("Specifies the name of the group, GroupName cannot be duplicated") . Select (). APIs (Requesthandlersel Ectors.basepackage ("Here is the package path you need to scan")) //Filter Build Links. paths (Pathselectors.any ()). Build (). Apiinfo (Apiinfo ()); } /*** the API info * *@returnAPI Info*/ Privateapiinfo Apiinfo () {return NewApiinfobuilder (). License ("Apache License Version 2.0"). Title ("Blogspot"). Description ("API Docs"). Contact (NewContact ("Tangzedong", "https://www.cnblogs.com/HackerBlog/", "[Email protected]"). Version ("1.0"). build (); }}
And then all the operations are done, isn't it simple? It's so simple.
Then start the Spring boot server and enter the URL on the Web page: http://localhost:8080/swagger-ui.html You can see the Swagger page.
Spring Boot Project Add Swagger 2.7.0 (two steps only)