当前位置:网站首页>Swagger -- the most popular API framework in the world
Swagger -- the most popular API framework in the world
2022-07-19 02:41:00 【Do you eat oil cake】
swagger characteristic
- Restful Api Online automatic document generation tool => Api Documentation and Apl Definition synchronization update
- Run directly and test online Api Interface
- Almost all languages are supported
Official website :API Documentation & Design Tools for Teams | Swagger
stay springboot Integration in the project swagger
1. Create a new one springboot(Web) project
2. Import correlation dependency ( We import here 2.9.2 Version of )
1)springfox-swagger2
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>2)springfox-swagger-ui
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>3. To configure Swagger->config
@Configuration
@EnableSwagger2 // Turn on swagger
public class SwaggerConfig {
}
4. test run : http://localhost:8300/swagger-ui.html


notes : If you visit swagger-ui.html When the page is , appear No handler found for GET /swagger-ui.html Inaccessible issues
reason :
This mistake , It is caused by the problem of resource mapping . We are visiting swagger-ui.html When the page is , This swagger-ui.html All related front-end static files are in springfox-swagger-ui-2.9.2.jar Inside . Directory as follows :

and Spring Boot Autoconfig itself does not automatically turn /swagger-ui.html This path is mapped to the corresponding directory META-INF/resources/ below , So we can't visit .
resolvent :
You need to add a configuration class ( Or in your original webMvcConfig in overwrite This addResourceHandlers Method , Can solve .
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}Swagger Configuration of
In the just written SwaggerConfig Class swagger Of Apl Basic information of the document
@Configuration
@EnableSwagger2 // Turn on swagger
public class SwaggerConfig {
// To configure swagger Of docket example
@Bean
public Docket docket(){
return new Docket(SWAGGER_2)// Version is swagger2
.groupName("szny")
.apiInfo(apiInfo()); //api Information
}
// To configure swagger Of api Information
private ApiInfo apiInfo(){
// The author information
Contact contact = new Contact("yk", "https://blog.csdn.net/weixin_72076848", "xx");
return new ApiInfo(" Digital agriculture system swagger file ",
" Digital agriculture system ",
"1.0",
"https://blog.csdn.net/weixin_72076848",
contact ,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList());
}
}
To configure swagger Scanning interface of
// To configure swagger Of docket example
@Bean
public Docket docket(){
return new Docket(SWAGGER_2)// Version is swagger2
.groupName("szny")
.apiInfo(apiInfo())
.select()
//RequestHandlerSelectors: Configure how to scan the interface
//basePackage: Scan the specified package
//any: Scan all none: Don't scan
.apis(RequestHandlerSelectors.basePackage("com.jpzh.bis.controller"))
//ant: Filter the specified path any: Filter all none: No filtering
//.paths(PathSelectors.any())
.build(); //api Information
}swagger Group function of , It is applicable to collaborative development within the project team
@Bean
public Docket docket1(){
return new Docket(SWAGGER_2)
.groupName("A");
}
@Bean
public Docket docket2(){
return new Docket(SWAGGER_2)
.groupName("B");
}
@Bean
public Docket docket3(){
return new Docket(SWAGGER_2)
.groupName("B");
}ok, After learning this, you can carry out simple swagger Integrated , Let's try !
边栏推荐
- Shortest circuit / secondary short circuit /k short circuit
- Method of JMeter connecting to database
- 解决WIN10连接共享打印机出现0x00000709的错误
- Tree array and St table
- [unity Editor Extension] quickly locate the specified files and paths of resources and scripts
- 2022.6.28-数据库-1.数据库的隔离级别
- Leetcode buckle classic topic - 82 Maximum rectangle in column chart
- status 500 reading AftersaleService#getAftersaleList(Long)+com. sun. proxy.$ Proxy214.getAftersaleList
- 使用JMeter测试基于WebSocket协议的服务
- Next array - circular section
猜你喜欢

Leetcode buckle classic question - 42 Connect rainwater

深入性能测试数据分析

通过Xshell7使用rz,sz命令上传下载文件

解决WIN10连接共享打印机出现0x00000709的错误

PowerStor500T报错0x01806803

Logical vulnerability - authentication vulnerability

Post man JSON script to JMX script of JMeter

Bugku---- regular matching, cookies

squid代理服务部署

InnoDB, MySQL structure, and the difference between the three kinds of deletion
随机推荐
SoloPi APP性能测试用
深入性能测试数据分析
并发虚拟用户、RPS、TPS的解读
安装.NET提示“无法建立到信任根颁发机构的证书链”(方法简单有下载地址)
Flask template injection
Shortest circuit / secondary short circuit /k short circuit
YUM仓库服务与PXE自动部署系统
ctfhub--ssrf
This article only commemorates the modulus of negative numbers
Experience in using flow playback tool Gor
Subnet division (see details)
Firewalld 防火墙
30分钟搞懂 HTTP 缓存
Jmeter接口测试之响应断言
ctfhub--ssrf
Logic vulnerability - login verification code security
JMeter response time test component & multi interface concurrency
Metersphere is based on JMeter distributed performance pressure testing platform
Jmeter beanshell实现把请求生成的参数化数据写入文件
After unity imports the FBX model, the rotation and position of the object will change automatically at runtime