Camel - Rest Component 集成 Swagger UI

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 {
    @Override
    public 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-path
        rest("/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技术(接口文档实时动态生成工具)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值