标签:关注 pen boot 自己 alt als sdn ase config
swagger是什么?swagger是一个后台人员专门测试的一个简单工具,特别适合做前后端分离的项目,之前我们一直都是用的postman,但是这个有点复杂,路径需要自己,而swagger则直接使用,接下来我们就直接上代码说一说swagger,文采不好往见谅!
1.首先需要两个jar包
<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.配置swagger核心类
@Configuration
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.pcitc.scl.business.productoil.service.controller")) //自己的包名
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("springboot利用swagger构建api文档")
.description("简单优雅的restfun风格,http://blog.csdn.net/saytime")
.termsOfServiceUrl("http://blog.csdn.net/saytime")
.version("1.0")
.build();
}
}3.springApppplication.java springBoot核心类中的配置
主要是在类上加注解@EnableSwagger2
最后直接
http://localhost:8080/swagger-ui.html
就可以看到自己的项目了,如果项目名称出不来或者项目启动不起来,请关注我的另一篇文章
标签:关注 pen boot 自己 alt als sdn ase config
原文地址:http://blog.51cto.com/itengxun/2139938