在项目中,需要对接口进行定义,生成文档,swagger是个不错的选择,使用起来也很方便
这里就来说说它的配置和使用
另外,还有raml-mocker,后期考虑在写一篇吧
第一步:pom.xml修改,引入springboot和swagger:
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
ch.qos.logback
logback-classic
org.springframework.boot
spring-boot-starter-thymeleaf
io.springfox
springfox-swagger2
2.7.0
第二步:从git上下载一个版本的swagger,地址如下:
https://github.com/swagger-api/swagger-ui/tree/v2.2.10
代码clone下来后,在本地打开,并将dist目录复制到项目中,如下:
image.png
第三步:我们配置下swagger的访问路径,添加swagger.properties,内容如下:
springfox.documentation.swagger.v2.path=/rest/api/doc
同时,修改index.html页面上请求的路径