在springboot中配置swagger

  • 1.Maven依賴
<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>

    1. swagger配置
image.png
@Configuration

@ConfigurationProperties(prefix ="swagger")

public class Swagger2 {

private boolean disable;

@Bean

    public Docket createRestApi() {

Predicate selector = PathSelectors.any();

if (disable) {

selector = PathSelectors.none();

}

return new Docket(DocumentationType.SWAGGER_2)

.apiInfo(apiInfo())

.select()

.apis(RequestHandlerSelectors.basePackage("com.coss"))

.paths(selector)

.build();

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("工具接口")

.version("1.0.0.")

.build();

}

public void setDisable(boolean disable) {

this.disable = disable;

}

}


  • 3.通過在application.yml文件中配置訪問的端口,就可以通過localhost:8081/swagger-ui.html訪問了
image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,275評論 6 342
  • jHipster - 微服務(wù)搭建 CC_簡書[http://www.itdecent.cn/u/be0d56c4...
    quanjj閱讀 931評論 0 2
  • 作者 Victor Grazi ,譯者 張健欣 發(fā)布于 2018年1月10日 引自:使用SpringBoot開啟微...
    重睛鳥閱讀 941評論 0 0
  • 回想當(dāng)初那個自負(fù)的自己,好可笑。真的是不想加班,還想能晉升,能漲工資。工作了3年后,明白了許多。沒有不辛苦就能掙到...
    加貝兒_1a46閱讀 167評論 0 0

友情鏈接更多精彩內(nèi)容