springmvc 整合 swagger2

1.在springmvc 中添加swagger2 的maven依赖


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




2.在Spring IOC 容器中注册swagger2的启动类


<bean id="swagger2Config" class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"></bean>




3.在springmvc中配置访问swagger2的静态页面的配置


 <mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/>  
 <mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>  


4.建立一个controller类


@Api(description = "用户列表")  注解整个类  现在里面的 description 属性已经过期
@ApiOperation(value = "sprimvc test", httpMethod = "GET", notes = "用于测试springmvc的方法")

注释一个Handel





启动项目,然后访问路径

http://localhost:8080/swagger-ui.html





好的,到这里就已经成功了


文章翻译自github官网


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值