SpringBoot+SpringCloud+vue+Element开发项目——集成Swagger文档


在pom.xml文件中添加Maven依赖

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

新建一个config包,并在其下面添加Swagger配置类SwaggerConfig.java。

@Configurable
@EnableSwagger2
public class SwaggerConfig {
 
    @Bean
    public Docket CreateRestApi(){
        return  new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().
                apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
    }
 
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder().build();
    }
}

在application启动类添加

@EnableSwagger2

启动页面测试

浏览器中访问http://localhost:8001/swagger-ui.html#/

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM