How SpringBoot integrate with Swagger?

Integrate a new routine things: lead jar package, change the configuration, a thief cool cool thief used.
Swagger this thing for me is not a strange thing, the use of Swagger does bring great convenience to research and development.
Personally I think it is a API interface documentation.
Before:
the back-end developers to write the interface documentation, some with written word, some editing Markdown, personal feeling some trouble.
Now:
With the swagger, the backend can define good interfaces, business logic temporarily do not have to write the interface can show up for front-end development.
Here Insert Picture Description
Of course, you can make use of swagger comment interfaces comment clearer, let's talk about how to integrate:

引jar

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.8.0</version>
    </dependency>

Configuration

/**
 * swagger 配置访问地址:http://localhost:8281/swagger-ui.html
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any()).build();
    }

    //构建api文档的详细信息函数
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("微信基础服务")
                //版本号
                .version("1.0")
                //描述
                .description("API 描述")
                .build();
    }

}

swagger of use

Notes concerning use:
Refer to: https://segmentfault.com/a/1190000015671612

Note:
the production environment we have to close the show swagger interface, just add swagger.show in the application configuration file to expose the switch control interface:
swagger.show = to true or swagger.show = false to control whether the interface showing

Summary:
master these, no problem developed, powerful functions related to swagger has yet to be excavated, easy to use many things to share.

Thank you for reading!

Published 253 original articles · won praise 76 · views 290 000 +

Guess you like

Origin blog.csdn.net/hongwei15732623364/article/details/85262259