Spring Boot 中带有 DSL 的 Apache Camel Rest 端点将 /camel 添加到路径中



我正在尝试构建一个模块以插入Spring Boot应用程序。这个模块应该公开一些 REST 端点,我正在尝试使用 Camel 构建它们,因为我不想向 web.xml 等添加内容。

restConfiguration().component("servlet")
      .contextPath("/my")
      .apiContextPath("/api-doc")
      .apiProperty("api.title", "My REST API")
      .apiProperty("cors", "true")
      .apiContextRouteId("my-api")
      .bindingMode(RestBindingMode.json);
rest("/my").description("My REST Services")
      .get("foo/{id}").route().routeId("foo")
      .to("direct:foo");
from("direct:foo")
      .process(new FooParamParser())
      .log("Done");

遇到的问题是,我必须在/camel/my/foo/123?status=abc 处点击它,而不是在/my/foo/123?status=abc 处点击它。

它这样做是因为它默认使用 Camel Servlet 作为 DSL 的 REST 端点,我对此很好,但我不希望它把"/camel"放在我路径的开头。我应该注意,无论有没有.component("servlet"),此行为都是相同的

有什么办法可以改变这一点吗?

您可以在 application.properties 或 application.yml 中控制这一点

例如

camel.component.servlet.mapping.contextPath=/api/*

参考 https://github.com/apache/camel/blob/master/examples/camel-example-spring-boot-rest-jpa/src/main/resources/application.yml

使用 Spring Boot 2.7.2+ 和 Apache Camel 3.18.0+,现在的密钥是:

camel.servlet.mapping.context-path=/api/*

而不是

camel.component.servlet.mapping.contextPath=/api/*

最新更新