用的多的简单方式是使用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