`
sillycat
  • 浏览: 2527603 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

WebFlux and Swagger Integration

 
阅读更多
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

分享到:
评论

相关推荐

    spring-boot-webflux-swagger-starter:一个示例项目,说明如何使用Swagger2记录Spring Boot Webflux

    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核心和Swagger UI集成轻松实现Java EE应用程序

    swagger-ui-integration是一个库,它允许您同时通过swagger公开应用程序的REST API的描述,并使用其描述性swagger提供访问UI(swagger-UI)的功能。 昂首阔步的lib链接: swaggerUI:3.14.1(对Tibor17表示感谢)...

    springboot-swagger-integration:SpringBoot整合Swagger自动化文档

    2. **配置Swagger**:在SpringBoot的主配置类或者专门的配置类上,使用`@EnableSwagger2WebMvc`或`@EnableSwagger2WebFlux`注解开启Swagger支持。然后创建一个配置Swagger的类,使用`@Configuration`和`@...

    swagger2Demo,swagger

    Swagger是一个强大的API开发工具,主要用于设计、构建、文档化和使用RESTful web服务。在这个名为"swagger2Demo"的项目中,我们看到作者利用Swagger 2创建了一个演示应用,目的是为了展示如何使用Swagger来调试接口...

    spring webflux使用的详细代码

    Spring WebFlux是Spring Framework 5.0引入的一个全新模块,它是对传统Spring MVC的补充,专注于非阻塞式、反应式编程模型。这个模型特别适用于高并发、低延迟的现代Web应用程序。在这个主题中,我们将深入探讨...

    swagger官方文档离线版

    Swagger官方文档离线版是开发人员和团队在不依赖互联网连接的情况下查阅Swagger 2.0规范的重要资源。Swagger是一个流行的API开发工具,它基于OpenAPI Specification(以前称为Swagger specification),用于设计、...

    swagger开启身份认证

    ### swagger开启身份认证 在现代Web开发中,API文档自动生成工具如Swagger变得越来越重要,它们不仅能够提高开发效率,还能够帮助团队更好地管理和维护API接口。然而,随着API暴露给外部用户,安全问题也日益突出。...

    swagger,基于swagger的前端UI实现

    现在市面上的swagger UI不足之处 1、原生UI显示的有些不够漂亮和清晰,特别是request 的model部分 2、每个服务都需要引入一套资源文件,不能作为一个中间件为其他API使用 3、默认通用配置繁琐,每个项目都需要复制...

    swagger2.zip

    springboot 2.2.7集成swagger2.9.2,并生成markdown格式API文档. &lt;!-- swagger2 依赖开始--&gt; &lt;!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --&gt; &lt;groupId&gt;io.springfox ...

    swaggerui.zip

    .description("API for demonstrating Swagger integration with SpringBoot") .version("1.0") .build(); } } ``` **4. 使用Swagger UI** 完成配置后,Swagger UI将在我们的应用中可用。启动SpringBoot应用,...

    swagger所有相关jar包

    Swagger是一个流行的API开发工具,主要用于构建、文档化和测试RESTful web服务。它提供了一种交互式的、基于HTTP的API接口,使得开发者可以轻松地理解并使用这些接口。Swagger通过JSON格式来描述API,使得服务的消费...

    swagger_java_swagger_

    Swagger 是一个流行的API开发工具,它提供了一套规范和实现,用于设计、构建、文档化和使用RESTful Web服务。在Java环境中,Swagger通常与Spring Boot框架结合使用,以简化API的开发和测试过程。本篇文章将深入探讨...

    swagger静态部分文件打包

    Swagger 是一个广泛使用的 API 设计和开发工具,它允许开发者以 YAML 或 JSON 格式定义 RESTful 风格的 Web 服务接口。这个压缩包文件 "swagger" 可能包含了 Swagger 的静态资源,这些资源主要用于展示和测试 API ...

    swagger在线文档转成word文档

    通过添加`springfox-swagger2`和`springfox-swagger-ui`依赖,我们可以在项目中启用Swagger UI,它是一个Web界面,能够展示API的详细信息。 ```xml &lt;groupId&gt;io.springfox &lt;artifactId&gt;springfox-swagger2 ...

    swaggerUI静态资源包

    Swagger UI 是一个强大的工具,用于交互式地展示和测试API接口。它基于Swagger规范,能够帮助开发者轻松地理解和使用API。在Spring框架中整合Swagger UI,可以为开发、测试和文档化RESTful服务提供极大的便利。这篇...

    swagger2依赖包

    Swagger2是一个广泛使用的API文档和测试工具,它允许开发者通过注解轻松地在Java应用程序中定义RESTful API接口。这个“swagger2依赖包”包含了Swagger2实现所需的关键组件,使得开发人员可以自动化生成API的客户端...

    swagger所需jar包大全

    Swagger是一个强大的API文档工具,它允许开发者通过注解在代码中定义RESTful API,并自动生成交互式的文档,便于测试和调试。在Spring MVC框架中,Swagger可以与之完美结合,帮助开发人员更轻松地管理API接口。这个...

    Swagger 自定义UI界面.doc

    Swagger 自定义UI界面 Swagger 是一个流行的 API 文档生成工具,能够自动生成 RESTful API 的文档,帮助开发者快速了解 API 的使用方法和参数信息。在本文中,我们将讨论如何使用 Swagger 在 Spring Boot 2.0 项目...

    Swagger接口导出Word.rar

    Swagger是一个流行的API文档工具,它允许开发者以结构化的方式定义和文档化RESTful API。在.NET环境中,Swagger(也称为Swashbuckle)为ASP.NET Web API提供了强大的支持,包括生成交互式的API文档。本教程将围绕...

    TP5集成swagger

    ### TP5集成Swagger知识点详解 #### 一、Swagger概述与工作原理 Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化RESTful风格的Web服务。它旨在解决的一个核心问题是API文档的生成和维护问题。对于...

Global site tag (gtag.js) - Google Analytics