基础API

swagger使用

2016-03-01  本文已影响761人  晨宇

实现后台自动生成文档,减少前后台沟通成本。spring mvc与swagger的集成

1. 下载https://github.com/mousycoder/server-api中的源代码

2. 在WEB-INF新建文件夹swagger,并将源码webapp下的css, images, lib, index.html, swagger-ui.js, swagger-ui.min.js拷贝到swagger文件夹下

3. 修改index.html, 将else中url的值设为你自己对应项目的地址

if (url && url.length > 1) {

url = url[1];

} else {

url = "http://localhost:8080/server-api/api-docs";

}

4. 新建一个类,可以拷贝源代码中的CustomJavaPluginConfig.class完成swagger配置

5. pom文件中添加引用的jar包

<dependency>

<groupId>com.mangofactory</groupId>

<artifactId>swagger-springmvc</artifactId>

<version>1.0.2</version>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-databind</artifactId>

<version>2.4.2</version>

</dependency>

6. 配置spring-security.xml,使得只有授权用户才能访问api文档。

感谢mousycoder的无私奉献

上一篇 下一篇

猜你喜欢

热点阅读