springBoot配置Swagger

1.在pom.xml中加入Swagger2的依赖

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${swagger.version}</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>${swagger.version}</version>
</dependency>

2.创建Swagger2配置类

@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket createResApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("blog.manager.web.bff"))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("博客管理系统")
                .description("RESTful API")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }
}
如图:

3.运行效果图

猜你喜欢

转载自blog.csdn.net/u010260737/article/details/83304476