Swagger的配置和集成
程序开发
2023-09-15 17:16:29
Swagger
首先我们需要了解swagger
1、SpringBoot集成Swagger
1、maven依赖
io.springfox springfox-swagger2 2.9.2
io.springfox springfox-swagger-ui 2.9.2
2、配置Swagger swaggerconfig
@Configuration
@EnableSwagger2//开启Swagger2
public class SwaggerConfig {
}
3、跑一下
localhost:8080/swagger-ui.html
2、配置Swagger
Swagger的bean实例Docket;
@Configuration
@EnableSwagger2
public class SwaggerConfig {//配置了Swagger的Docket的bean实例@Beanpublic Docket docket(){return new Docket(DocumentationType.SWAGGER_12).apiInfo(apiInfo());}//配置swagger的信息 = apiinfoprivate ApiInfo apiInfo(){//作者信息Contact contact = new Contact("满世繁华", "https://blog.csdn.net/qq_34037264", "1499462668@qq.com");return new ApiInfo("繁华的Swagger API文档","好好学习 天天向上","1.0","https://blog.csdn.net/qq_34037264",contact,"Apache 2.0","http://www.apache.org/licenses/LICENSE-2.0",new ArrayList());}
}
3、配置swagger扫描接口
Docket().select();
//配置了Swagger的Docket的bean实例@Beanpublic Docket docket(){return new Docket(DocumentationType.SWAGGER_12).apiInfo(apiInfo()).select()//RequestHandlerSelectors , 配置扫描接口的方式//basepackage:指定要扫描的包//any():全部扫描//none():不扫描//withClassAnnotation():扫描类上的注解,参数是一个注解的反射对象//withMethodAnnotation():扫描方法上的注解.apis(RequestHandlerSelectors.any())//paths():过滤什么路径//.paths(PathSelectors.ant("msfh/**")).build();}
4、配置是否启动swagger
//配置了Swagger的Docket的bean实例@Beanpublic Docket docket(){return new Docket(DocumentationType.SWAGGER_12).apiInfo(apiInfo()).enable(true)//enable是否启用swagger ,如果为false , 则swagger不能再浏览器中访问.select()//RequestHandlerSelectors , 配置扫描接口的方式//basepackage:指定要扫描的包//any():全部扫描//none():不扫描//withClassAnnotation():扫描类上的注解,参数是一个注解的反射对象//withMethodAnnotation():扫描方法上的注解.apis(RequestHandlerSelectors.any())//paths():过滤什么路径//.paths(PathSelectors.ant("msfh/**")).build();}
标签:
相关文章
-
无相关信息