参考博客地址:
在线文档:http://blog.didispace.com/springbootswagger2/
离线文档:http://www.jianshu.com/p/af7a6f29bf4f
用到的技术spring boot + maven + swagger2 + spring doc,swagger2生成整个文档,spring doc是测试一个个实例接口,首先是利用将swagger2在线文档的json数据得到
,然后将json数据和spring doc得到的数据一起转化为asciidoc格式的数据,然后将asciidoc格式的数据转化为html和pdf格式等等
spring boot利用swagger2生成在线文档:
1.在pom.xml中加入swagger2的jar包,这里用的2.6.1的版本,2.7版本试了下有版本兼容的问题
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency>
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency>
2.配置swagger2的配置文件
新建一个类叫什么都行:
@Configuration@EnableSwagger2public class Swagger2 {
@Bean public Docket createTestApi() throws Exception{ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.ssm.MyServer.web")) .paths(PathSelectors.any()) .build(); }
public ApiInfo apiInfo() throws Exception{ return new ApiInfoBuilder() .title("Spring Boot中使用Swagger2构建restful APIs") .description("这是我的项目") .termsOfServiceUrl("http://www.wust.edu.cn/default.html") .version("1.0") .build(); }
}
3.在具体的restful接口上面配置文档
涉及到项目技术不写了看上面两个地址就可以配置了
遗留问题:
1.spring doc的测试所有接口是怎么写的,不会是一个一个的写吧?有待实验
**************************************************************
5个月后再来看找不到我写的代码了,还是把原来的代码上传一份吧https://github.com/waterlufei/spring-boot,下面的QA-server
转载于:https://www.cnblogs.com/waterlufei/p/6941679.html
相关资源:spring-boot,swagger2,生成html及中文pdf示例