繁体   English   中英

Apache Camel Rest 端点与 Spring 中的 DSL 引导将 /camel 添加到路径

[英]Apache Camel Rest endpoint with DSL in Spring Boot adds /camel to the path

我正在尝试构建一个模块以插入 Spring 引导应用程序。 这个模块应该暴露一些 REST 端点,我正在尝试用 Camel 构建它们,因为我不想向 web.Z0F635D0E0F3874FFF8B581C132E6C7AZ 等添加东西。

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/*

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM