Spring Integrated Swagger,java Auto-Generate API documentation

Source: Internet
Author: User

Bo Master is very lazy ...

Swagger Official website: Http://swagger.io

GitHub Address: Https://github.com/swagger-api

Official Note document: http://docs.swagger.io/swagger-core/apidocs/index.html

Swagger-ui Address: Https://github.com/swagger-api/swagger-ui

Swagger final

Well, start by saying how spring configures Swagger 1.pom.xml to introduce the required jar packages
<!--Building a restful API I'm 2.6.1 this version . -<Dependency>    <groupId>Io.springfox</groupId>    <Artifactid>Springfox-swagger2</Artifactid>    <version>${swagger2.version}</version></Dependency><Dependency>    <groupId>Io.springfox</groupId>    <Artifactid>Springfox-swagger-ui</Artifactid>    <version>${swagger2.version}</version></Dependency>
2. Scan the package where your Swagger2config.java is located
<!---<Context:component-scan   base-package  = "Com.nickwilde.microtrain.common.config.swagger"/>
3.swagger2config.java[class name Customization]
 PackageCom.nickwilde.microtrain.common.config.swagger2;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;/** * @authorNickwilde *@version2018/1/18 10:23 * @description: Swagger2config * TODO in a sentence description*/@Configuration @enableswagger2 Public classswagger2config{@Bean PublicDocket API () {return NewDocket (documentationtype.swagger_2). Forcodegeneration (true). Select (). APIs (Requesthandlerselectors.any ())//Filter Build Links. paths (Pathselectors.any ()). Build (). Apiinfo (Apiinfo ()); }    //API Interface Author related information    Privateapiinfo Apiinfo () { Contact Contact=NewContact ("Nickwilde", "", "[email protected]"); Apiinfo Apiinfo=NewApiinfobuilder (). License ("Apache License Version 2.0"). Title ("Unexpectedly system"). Description ("Interface Documentation"). Contact. Version ("1.0"). build (); returnApiinfo; }}
4. Add additional annotations to your controller (not added)
// Httpmehtod if not defined, then swagger will have to enumerate all the request methods of the interface. true //Parameter definition: Type.. Kind of, this is basic simple, the rest of the Look API bar ~

Spring Integrated Swagger,java Auto-Generate API documentation

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.