- 浏览: 2550858 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
WebFlux and Swagger Integration
Try some samples
> git clone https://github.com/pgilad/spring-boot-webflux-swagger-starter
Go to that Project and Compile
> gradle clean build
List the Version
> jenv versions
system
* 1.8 (set by /usr/local/opt/jenv/version)
1.8.0.161
10.0
10.0.2
11.0
11.0.2
oracle64-1.8.0.161
oracle64-10.0.2
oracle64-11.0.2
Switch the version
> jenv local 11.0
Check version
> java -version
java version "11.0.2" 2019-01-15 LTS
Start the service
> gradle bootRun
After that, we can visit the page
http://localhost:8080/swagger-ui.html
In my netty web flux project, here are the key changes
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>swagger-snapshots</id>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
Important SwaggerConfig.java class
package com.sillycat.webfluxlatency.config;
import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;
@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(basePackage("com.sillycat.webfluxlatency.web"))
.paths(PathSelectors.any()).build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo("RESTful API", null, "API V1", null, null, null, null,
Collections.emptyList());
}
}
Important WebFluxConfig.java
package com.sillycat.webfluxlatency.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
@Configuration
public class WebfluxConfig implements WebFluxConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html**")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
After that, we can visit these URLs to verify, it works well.
http://localhost:8083/actuator
http://localhost:8083/hello/1000
http://localhost:8083/swagger-ui.html#/
References:
https://code.massoudafrashteh.com/spring-boot-webflux-with-RDBMS/
https://stackoverflow.com/questions/48317431/generate-webservice-description-with-swagger-in-spring-webflux-environnment
https://github.com/deblockt/springfox/tree/feature/webflux
https://github.com/deblockt/springfox/tree/feature/webflux/springfox-spring-webflux
https://github.com/pgilad/spring-boot-webflux-swagger-starter
Try some samples
> git clone https://github.com/pgilad/spring-boot-webflux-swagger-starter
Go to that Project and Compile
> gradle clean build
List the Version
> jenv versions
system
* 1.8 (set by /usr/local/opt/jenv/version)
1.8.0.161
10.0
10.0.2
11.0
11.0.2
oracle64-1.8.0.161
oracle64-10.0.2
oracle64-11.0.2
Switch the version
> jenv local 11.0
Check version
> java -version
java version "11.0.2" 2019-01-15 LTS
Start the service
> gradle bootRun
After that, we can visit the page
http://localhost:8080/swagger-ui.html
In my netty web flux project, here are the key changes
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>swagger-snapshots</id>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
Important SwaggerConfig.java class
package com.sillycat.webfluxlatency.config;
import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;
@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(basePackage("com.sillycat.webfluxlatency.web"))
.paths(PathSelectors.any()).build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo("RESTful API", null, "API V1", null, null, null, null,
Collections.emptyList());
}
}
Important WebFluxConfig.java
package com.sillycat.webfluxlatency.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
@Configuration
public class WebfluxConfig implements WebFluxConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html**")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
After that, we can visit these URLs to verify, it works well.
http://localhost:8083/actuator
http://localhost:8083/hello/1000
http://localhost:8083/swagger-ui.html#/
References:
https://code.massoudafrashteh.com/spring-boot-webflux-with-RDBMS/
https://stackoverflow.com/questions/48317431/generate-webservice-description-with-swagger-in-spring-webflux-environnment
https://github.com/deblockt/springfox/tree/feature/webflux
https://github.com/deblockt/springfox/tree/feature/webflux/springfox-spring-webflux
https://github.com/pgilad/spring-boot-webflux-swagger-starter
发表评论
-
Update Site will come soon
2021-06-02 04:10 1677I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 315I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 475NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 367Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 367Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 335Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 429Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 434Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 373Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 454VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 384Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 475NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 421Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 336Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 246GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 450GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 325GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 312Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 317Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 292Serverless with NodeJS and Tenc ...
相关推荐
spring-boot-webflux-swagger-starter 一个示例项目,说明如何使用Swagger2记录Spring Boot Webflux要求Java 11安装$ git clone https://github.com/pgilad/spring-boot-webflux-swagger-starter.git用法$ gradle ...
swagger-ui-integration是一个库,它允许您同时通过swagger公开应用程序的REST API的描述,并使用其描述性swagger提供访问UI(swagger-UI)的功能。 昂首阔步的lib链接: swaggerUI:3.14.1(对Tibor17表示感谢)...
2. **配置Swagger**:在SpringBoot的主配置类或者专门的配置类上,使用`@EnableSwagger2WebMvc`或`@EnableSwagger2WebFlux`注解开启Swagger支持。然后创建一个配置Swagger的类,使用`@Configuration`和`@...
Swagger是一个强大的API开发工具,主要用于设计、构建、文档化和使用RESTful web服务。在这个名为"swagger2Demo"的项目中,我们看到作者利用Swagger 2创建了一个演示应用,目的是为了展示如何使用Swagger来调试接口...
Spring WebFlux是Spring Framework 5.0引入的一个全新模块,它是对传统Spring MVC的补充,专注于非阻塞式、反应式编程模型。这个模型特别适用于高并发、低延迟的现代Web应用程序。在这个主题中,我们将深入探讨...
### swagger开启身份认证 在现代Web开发中,API文档自动生成工具如Swagger变得越来越重要,它们不仅能够提高开发效率,还能够帮助团队更好地管理和维护API接口。然而,随着API暴露给外部用户,安全问题也日益突出。...
Swagger官方文档离线版是开发人员和团队在不依赖互联网连接的情况下查阅Swagger 2.0规范的重要资源。Swagger是一个流行的API开发工具,它基于OpenAPI Specification(以前称为Swagger specification),用于设计、...
springboot 2.2.7集成swagger2.9.2,并生成markdown格式API文档. <!-- swagger2 依赖开始--> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <groupId>io.springfox ...
.description("API for demonstrating Swagger integration with SpringBoot") .version("1.0") .build(); } } ``` **4. 使用Swagger UI** 完成配置后,Swagger UI将在我们的应用中可用。启动SpringBoot应用,...
Swagger 是一个广泛使用的 API 设计和开发工具,它允许开发者以 YAML 或 JSON 格式定义 RESTful 风格的 Web 服务接口。这个压缩包文件 "swagger" 可能包含了 Swagger 的静态资源,这些资源主要用于展示和测试 API ...
现在市面上的swagger UI不足之处 1、原生UI显示的有些不够漂亮和清晰,特别是request 的model部分 2、每个服务都需要引入一套资源文件,不能作为一个中间件为其他API使用 3、默认通用配置繁琐,每个项目都需要复制...
Swagger是一个流行的API开发工具,主要用于构建、文档化和测试RESTful web服务。它提供了一种交互式的、基于HTTP的API接口,使得开发者可以轻松地理解并使用这些接口。Swagger通过JSON格式来描述API,使得服务的消费...
Swagger 是一个流行的API开发工具,它提供了一套规范和实现,用于设计、构建、文档化和使用RESTful Web服务。在Java环境中,Swagger通常与Spring Boot框架结合使用,以简化API的开发和测试过程。本篇文章将深入探讨...
通过添加`springfox-swagger2`和`springfox-swagger-ui`依赖,我们可以在项目中启用Swagger UI,它是一个Web界面,能够展示API的详细信息。 ```xml <groupId>io.springfox <artifactId>springfox-swagger2 ...
Swagger UI 是一个强大的工具,用于交互式地展示和测试API接口。它基于Swagger规范,能够帮助开发者轻松地理解和使用API。在Spring框架中整合Swagger UI,可以为开发、测试和文档化RESTful服务提供极大的便利。这篇...
Swagger2是一个广泛使用的API文档和测试工具,它允许开发者通过注解轻松地在Java应用程序中定义RESTful API接口。这个“swagger2依赖包”包含了Swagger2实现所需的关键组件,使得开发人员可以自动化生成API的客户端...
Swagger是一个强大的API文档工具,它允许开发者通过注解在代码中定义RESTful API,并自动生成交互式的文档,便于测试和调试。在Spring MVC框架中,Swagger可以与之完美结合,帮助开发人员更轻松地管理API接口。这个...
Swagger 是一个用于生成、描述和调用 RESTful 接口的 Web 服务。通俗的来讲,Swagger 就是将项目中所有(想要暴露的)接口展现在页面上,并且可以进行接口调用和测试的服务。swagger可以将项目中所有的接口展现在...
Swagger是一个流行的API文档工具,它允许开发者以结构化的方式定义和文档化RESTful API。在.NET环境中,Swagger(也称为Swashbuckle)为ASP.NET Web API提供了强大的支持,包括生成交互式的API文档。本教程将围绕...
Swagger 自定义UI界面 Swagger 是一个流行的 API 文档生成工具,能够自动生成 RESTful API 的文档,帮助开发者快速了解 API 的使用方法和参数信息。在本文中,我们将讨论如何使用 Swagger 在 Spring Boot 2.0 项目...