【发布时间】:2020-06-11 11:21:10
【问题描述】:
我有一个 camel-spring-boot 项目,我在其中使用 Spring 的 @ConfigurationProperties 从 yml 文件加载目标 url。由于我的目的地是 HTTP url,因此我使用的是 camel-http4 组件。
现在我的 URL 是 https://example.com/students/{id}/subject/{name},这意味着我必须将 id 和 name 参数作为路径变量(而不是查询参数)传递。我的问题是如何传递这些参数? [注意:我不能将 URL 放在 DSL 或 XML 中,它必须在 application.yml 中]
但是,作为一种解决方案
//in some processor before toD()
headers.put("id", id);
headers.put("name", name);
//in yml
destination: https4://example.com/students/${header.id}/subject/${header.name}
但是在从 yml 加载此属性时,Spring 尝试将 ${header.id} 评估为 Spel 表达式(并抛出找不到它的错误),正如我提到的那样,它是 Camel 的简单表达式。如果我使用 DSL,则相同的表达式适用于 toD(),但不适用于 yml。
请告诉我,我的方法是否正确?如果是这样,那我该如何摆脱这个问题。提前致谢。
【问题讨论】:
标签: spring-boot apache-camel camel-http