小伙伴大家好,今天小编为大家介绍一个简单的测试工具swagger2。大家以前进行测试都是在浏览器里面或者一些工具(postman等)进行测试,这样稍微有点麻烦。大家了解下swagger.
1.在pom里面添加jar依赖,这里面选的swagger2是版本2.8.0
io.springfox
springfox-swagger2
2.8.0
io.springfox
springfox-swagger-ui
2.8.0
2.添加配置文件SwaggerConfig
@EnableSwagger2
@Configuration
public class SwaggerConfig {
//是否开启swagger,正式环境一般是需要关闭的,可根据springboot的多环境配置进行设置
@Value(value = "${swagger.enabled}")
Boolean swaggerEnabled;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
// 是否开启
.enable(swaggerEnabled).select()
// 扫描的路径包
.apis(RequestHandlerSelectors.basePackage("com.study.springcloud"))
// 指定路径处理PathSelectors.any()代表所有的路径
.paths(PathSele