springmvc 整合 swagger2

来源:互联网 发布:网络社会组织 编辑:程序博客网 时间:2024/05/19 12:25
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官网


原创粉丝点击