【问题标题】:Why property doesn't get evaluated correctly in Camel 3.7.3?为什么在 Camel 3.7.3 中无法正确评估属性?
【发布时间】:2021-03-17 13:19:22
【问题描述】:

我有路线

String XYZ = "xyz";

from(URL_A)
  .bean(PropertiesSetterBean.class)
  .to("${property." + XYZ + "}")

PropertiesSetterBean 在哪里:

@Component
class PropertiesSetterBean {
  public void copyProperties(@Headers Map<String, Object> headers, @ExchangeProperties Map<String, Object> properties) {
    properties.put("xyz", "direct:test")
  }
}

我得到的错误:

在以下位置创建路由 route1 失败:>>> DynamicTo[${property.xyz}]

看起来bean 没有被执行。

我使用骆驼:3.7.3,spring-boot:2.4.3,java:11

我做的步骤:

  • 我阅读了迁移指南
  • 查看了 GitHub 上可用的代码 sn-ps
  • 搜索 StackOverflow
  • 与同事交谈

我查看了类似的issue

而且,我仍然无法对问题进行分类。

我做错了什么?

更新 1

我添加了处理器:

.process(exchange -> {
  System.out.println("This is my property: " + exchange.getProperty("xyz"));
})

它有效。与此同时,我仍然无法在 Camel 中使用 simple DSL 检索此属性。

【问题讨论】:

  • 不应该properties.put("xyz", "direct:test")properties.put("property.xyz", "direct:test")
  • @Lino,我不知道在 Camel 3.7.3 中应该是什么样子,但我发布的语法在 Camel 2.X.X 中是有效的

标签: java spring-boot apache-camel migration apache-camel-3


【解决方案1】:

经过几个小时的搜索没有结果,我遇到了old post

要访问该属性,我需要使用"${exchangeProperty." + XYZ + "}"

注意:

  • 它适用于 Camel 2.X.X,因此请注意此更改。
  • 如果 Spring 和 Camel 占位符之间发生冲突,请使用 $simple 而不是 $
  • 在 Camel 3.X.X 中,您需要检查属性的位置并将其重新指向 exchangeProperty

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多