Use swagger to generate interface documentation in spring boot

Source: Internet
Author: User

1. Dependency Packages

<dependency>    <groupId>io.springfox</groupId>    <artifactid>springfox-swagger-ui </artifactId>    <version>2.6.1</version></dependency><dependency>    < groupid>io.springfox</groupid>    <artifactId>springfox-swagger2</artifactId>    < Version>2.6.1</version></dependency>

2. Configuration Classes

 PackageCom.shinyway.workflow;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.spi.DocumentationType;ImportSpringfox.documentation.spring.web.plugins.Docket;ImportSpringfox.documentation.swagger2.annotations.EnableSwagger2, @Configuration @enableswagger2 Public classswagger2configuration {@Bean PublicDocket Createrestapi () {return NewDocket (documentationtype.swagger_2). Apiinfo (Apiinfo ()). Select (). APIs (Requesthandlerselectors.basepackage ("Com.shinyway"). Paths (Pathselectors.any ()). build (); }    Privateapiinfo Apiinfo () {return NewApiinfobuilder (). Title ("Approval Platform API"). Description ("Approval Platform API"). Version ("1.0"). build (); }}

Add annotations to the methods in 3.controller

    @ApiOperation (value= "Get approval list (HTML format)", notes= "get a comment list by business number")    @ApiImplicitParams ({            True , DataType = "string"),            true, DataType = "string")    })

4. If a method or a whole class does not need to provide documentation, you can add @apiignore annotations to the method or class

Use swagger to generate interface documentation in spring boot

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.