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
这里写图片描述

猜你喜欢

转载自blog.csdn.net/zh15732621679/article/details/80973145