Camel - Rest Component 集成 Swagger UI

2024-04-25 18:32

本文主要是介绍Camel - Rest Component 集成 Swagger UI,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Camel - Rest Component 集成 Swagger UI

  • 1. Spring boot 集成 Swagger UI
    • 1.1 pom配置
    • 1.2 访问swagger ui
  • 2. Camel配置并启用Rest服务
    • 2.1 pom配置
    • 2.2 配置并启动jetty服务
    • 2.3 启动并获取swagger api信息
  • 3. 测试
  • 参考

1. Spring boot 集成 Swagger UI

1.1 pom配置

本示例通过webjar的方式集成swagger UI。
swagger-ui版本为2.2.10.

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.3.5.RELEASE</version>
</dependency>
<dependency><groupId>org.webjars</groupId><artifactId>swagger-ui</artifactId><version>2.2.10</version>
</dependency>
<dependency><groupId>org.webjars</groupId><artifactId>webjars-locator</artifactId><version>0.40</version>
</dependency>

配置spring boot 默认启动 tomcat 服务器,启动端口配置为 8088

server.port=8088

1.2 访问swagger ui

http://localhost:8088/webjars/swagger-ui/index.html#/
在这里插入图片描述

2. Camel配置并启用Rest服务

2.1 pom配置

<!-- camel -->
<dependency><groupId>org.apache.camel.springboot</groupId><artifactId>camel-spring-boot-starter</artifactId><version>3.6.0</version>
</dependency>
<dependency><groupId>org.apache.camel.springboot</groupId><artifactId>camel-jetty-starter</artifactId><version>3.6.0</version>
</dependency>
<dependency><groupId>org.apache.camel</groupId><artifactId>camel-swagger-java</artifactId><version>3.6.0</version>
</dependency>

2.2 配置并启动jetty服务

配置jetty服务,端口为8080,同时支持 swagger api 服务。
代码参考 https://github.com/ttyy1112/Camel-In-Action-3.3.0/tree/master/spring-app/rest-camel-springboot-test

public class OrderRoute extends RouteBuilder {@Overridepublic void configure() throws Exception {restConfiguration().component("jetty").port(8080)//Enable swagger endpoint..apiContextPath("/swagger") //swagger endpoint path.apiContextRouteId("swagger") //id of route providing the swagger endpoint//Swagger properties.contextPath("/api") //base.path swagger property; use the mapping path set for CamelServlet.apiProperty("api.title", "Swagger UI with Apache Camel-Jetty").apiProperty("api.version", "1.0").apiProperty("api.contact.name", "ATang").apiProperty("api.contact.email", "ATang@atang.com").apiProperty("api.contact.url", "https://atang.com/").apiProperty("host", "") //by default 0.0.0.0.apiProperty("port", "8080").apiProperty("schemes", "").apiProperty("cors", "true");// rest services under the orders context-pathrest("/orders")// need to specify the POJO types the binding is using (otherwise json binding defaults to Map based).get("{id}").outType(Order.class).to("bean:orderService?method=getOrder(${header.id})")// need to specify the POJO types the binding is using (otherwise json binding defaults to Map based).post().type(Order.class).to("bean:orderService?method=createOrder")// need to specify the POJO types the binding is using (otherwise json binding defaults to Map based).put().type(Order.class).to("bean:orderService?method=updateOrder").delete("{id}").to("bean:orderService?method=cancelOrder(${header.id})");}
}

2.3 启动并获取swagger api信息

通过访问 http://localhost:8080/api/swagger ,可以获取swagger api信息。
在这里插入图片描述

3. 测试

在这里插入图片描述

参考

Integrate Swagger with Apache Camel-Servlet.
Spring Boot, Apache Camel, and Swagger UI
SWAGGER JAVA
集成Open API
Swagger技术(接口文档实时动态生成工具)

这篇关于Camel - Rest Component 集成 Swagger UI的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/935463

相关文章

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

如何在Spring Boot项目中集成MQTT协议

《如何在SpringBoot项目中集成MQTT协议》本文介绍在SpringBoot中集成MQTT的步骤,包括安装Broker、添加EclipsePaho依赖、配置连接参数、实现消息发布订阅、测试接口... 目录1. 准备工作2. 引入依赖3. 配置MQTT连接4. 创建MQTT配置类5. 实现消息发布与订阅

SpringBoot集成LiteFlow工作流引擎的完整指南

《SpringBoot集成LiteFlow工作流引擎的完整指南》LiteFlow作为一款国产轻量级规则引擎/流程引擎,以其零学习成本、高可扩展性和极致性能成为微服务架构下的理想选择,本文将详细讲解Sp... 目录一、LiteFlow核心优势二、SpringBoot集成实战三、高级特性应用1. 异步并行执行2

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

Swagger在java中的运用及常见问题解决

《Swagger在java中的运用及常见问题解决》Swagger插件是一款深受Java开发者喜爱的工具,它在前后端分离的开发模式下发挥着重要作用,:本文主要介绍Swagger在java中的运用及常... 目录前言1. Swagger 的主要功能1.1 交互式 API 文档1.2 客户端 SDK 生成1.3

使用vscode搭建pywebview集成vue项目实践

《使用vscode搭建pywebview集成vue项目实践》:本文主要介绍使用vscode搭建pywebview集成vue项目实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录环境准备项目源码下载项目说明调试与生成可执行文件核心代码说明总结本节我们使用pythonpywebv

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

Maven项目中集成数据库文档生成工具的操作步骤

《Maven项目中集成数据库文档生成工具的操作步骤》在Maven项目中,可以通过集成数据库文档生成工具来自动生成数据库文档,本文为大家整理了使用screw-maven-plugin(推荐)的完... 目录1. 添加插件配置到 pom.XML2. 配置数据库信息3. 执行生成命令4. 高级配置选项5. 注意事

Java集成Onlyoffice的示例代码及场景分析

《Java集成Onlyoffice的示例代码及场景分析》:本文主要介绍Java集成Onlyoffice的示例代码及场景分析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 需求场景:实现文档的在线编辑,团队协作总结:两个接口 + 前端页面 + 配置项接口1:一个接口,将o