Spring Boot Project Add Swagger 2.7.0 (two steps only)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.