用的多的简单方式是使用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
![这里写图片描述](https://img-blog.csdn.net/20180709162022260?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poMTU3MzI2MjE2Nzk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)