SSM框架搭建(二)--整合swagger

描述

用的多的簡單方式是使用postman進行接口測試,這種測試需要開發人員自己輸入url,參數等信息,使用swagger項目啓動後通過swagger界面就可直接看到對應的controller及其下的接口,例如一些需要輸入某個實體的參數直接就給出了model,只需要修改參數即可測試,方便,快捷。

添加jar包依賴

在web層的pom文件中添加swagger的jar包依賴

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

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

配置bean

在spring-mvc.xml文件中添加swagger的bean

<bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/>
    <mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/>
    <mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>

訪問swagger


項目發佈地址/swagger-ui.html,例如,在我本地是http://localhost:8080/swagger-ui.html
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章