SSM配置Swagger 超简单

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuzailin/article/details/81915244

1,添加依赖

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

2,SpringMvc文件中添加配置

<!--添加swagger配置-->
<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/**"/>

或者

<bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/> 
<mvc:annotation-driven />
    <!-- 2.静态资源默认servlet配置
        (1)加入对静态资源的处理:js,gif,png
        (2)允许使用"/"做整体映射
     -->
    <mvc:default-servlet-handler/>

3,访问地址

http://IP:port/web-obj-name/swagger-ui.html

具体控制器配置注解请自行了解

猜你喜欢

转载自blog.csdn.net/xuzailin/article/details/81915244
今日推荐