用的多的簡單方式是使用postman進行接口測試,這種測試需要開發人員自己輸入url,參數等信息,使用swagger項目啓動後通過swagger界面就可直接看到對應的controller及其下的接口,例如一些需要輸入某個實體的參數直接就給出了model,只需要修改參數即可測試,方便,快捷。
在web層的pom文件中添加swagger的jar包依賴
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
在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-ui.html,例如,在我本地是http://localhost:8080/swagger-ui.html