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