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

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

【区块链 + 人才服务】区块链集成开发平台 | FISCO BCOS应用案例

随着区块链技术的快速发展,越来越多的企业开始将其应用于实际业务中。然而,区块链技术的专业性使得其集成开发成为一项挑战。针对此,广东中创智慧科技有限公司基于国产开源联盟链 FISCO BCOS 推出了区块链集成开发平台。该平台基于区块链技术,提供一套全面的区块链开发工具和开发环境,支持开发者快速开发和部署区块链应用。此外,该平台还可以提供一套全面的区块链开发教程和文档,帮助开发者快速上手区块链开发。

【Shiro】Shiro 的学习教程(三)之 SpringBoot 集成 Shiro

目录 1、环境准备2、引入 Shiro3、实现认证、退出3.1、使用死数据实现3.2、引入数据库,添加注册功能后端代码前端代码 3.3、MD5、Salt 的认证流程 4.、实现授权4.1、基于角色授权4.2、基于资源授权 5、引入缓存5.1、EhCache 实现缓存5.2、集成 Redis 实现 Shiro 缓存 1、环境准备 新建一个 SpringBoot 工程,引入依赖:

springboot 整合swagger

没有多余废话,就是干 spring-boot 2.7.8 springfox-boot-starter 3.0.0 结构 POM.xml <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/

系统架构师-ERP+集成

ERP   集成平台end:就懒得画新的页

Spring Boot集成Tess4J实现OCR

1.什么是Tess4j? Tesseract是一个开源的光学字符识别(OCR)引擎,它可以将图像中的文字转换为计算机可读的文本。支持多种语言和书面语言,并且可以在命令行中执行。它是一个流行的开源OCR工具,可以在许多不同的操作系统上运行。Tess4J是一个基于Tesseract OCR引擎的Java接口,可以用来识别图像中的文本,说白了,就是封装了它的API,让Java可以直接调用。 Tess

使用Spring Boot集成Spring Data JPA和单例模式构建库存管理系统

引言 在企业级应用开发中,数据库操作是非常重要的一环。Spring Data JPA提供了一种简化的方式来进行数据库交互,它使得开发者无需编写复杂的JPA代码就可以完成常见的CRUD操作。此外,设计模式如单例模式可以帮助我们更好地管理和控制对象的创建过程,从而提高系统的性能和可维护性。本文将展示如何结合Spring Boot、Spring Data JPA以及单例模式来构建一个基本的库存管理系统

Spring Boot集成PDFBox实现电子签章

概述 随着无纸化办公的普及,电子文档的使用越来越广泛。电子签章作为一种有效的身份验证方式,在很多场景下替代了传统的纸质文件签名。Apache PDFBox 是一个开源的Java库,可以用来渲染、生成、填写PDF文档等操作。本文将介绍如何使用Spring Boot框架结合PDFBox来实现电子签章功能。 准备工作 环境搭建:确保你的开发环境中安装了JDK 8或更高版本,并且配置好了Maven或

springboot+maven搭建的项目,集成单元测试

springboot+maven搭建的项目,集成单元测试 1.在pom.xml文件中引入单元测试的依赖包 <!--单元测试依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></depen

Golang GUI入门——andlabs ui

官方不提供gui标准库,只好寻求第三方库。 https://github.com/google/gxui 这个gui库是谷歌内部人员提供的,并不是谷歌官方出品,现在停止维护,只好作罢。 第三方gui库 找了好多,也比较了好多,最终决定使用的是还是 https://github.com/andlabs/ui 相信golang gui还会发展的更好,期待更优秀的gui库 由于andlabs