【问题标题】:Spring Boot properties usage in Apache Camel routeApache Camel 路由中的 Spring Boot 属性使用
【发布时间】:2017-08-08 22:17:23
【问题描述】:

这可以在 Apache Camel 路由中使用 Spring Boot 属性吗? @Value 工作正常,但这是否可以直接放置在表达式的占位符中。

更新:我知道 PropertiesComponent,但除了 Applicaiton.yml 之外,这将是我不喜欢的另一种配置。

application.yml

sftp:
  host:     10.10.128.128
  user:     ftpuser1
  password: ftpuser1password  
  path:     /tmp/inputfile/test1

Spring Boot Apache Camel 路线:

 @Value("${sftp.user}")
    private String sftpUser;

    @Value("${sftp.host}")
    private String sftpHost;

    @Value("${sftp.password}")
    private String sftpPassword;

    @Value("${sftp.path}")
    private String sftpInPath;

    from("sftp://"+sftpUser+"@"+sftpHost+sftpInPath+"?delete=true&password="+sftpPassword)
//this is working

    from("sftp://${sftp.user}@${sftp.host}${sftp.path}?password=${sftp.password}")
// is this possible something like this?

【问题讨论】:

  • 你试过了吗?
  • 是的,它不起作用,它说是空的。也无法绑定@ByeBye 感谢回复
  • @DariusX。感谢您的回复。

标签: java spring-boot apache-camel


【解决方案1】:

您可以像这样在 Camel 中使用属性占位符 (http://camel.apache.org/properties.html):

from("sftp://{{sftp.user}}@{{sftp.host}}{{sftp.path}}?password={{sftp.password}}")

【讨论】:

  • 谢谢我会检查这个
【解决方案2】:

您可以像这样注入完整链接,而不是将所有属性注入到单独的字段中:

@Value("#{'sftp://'+'${sftp.user}'+'@'+'${sftp.host}'+'${sftp.path}'+'?delete=true&password='+'${sftp.password}'}")
private String fullLink;

然后,你可以在from方法中使用它。

【讨论】:

  • 感谢您的回复。这很有帮助。
【解决方案3】:

尚未在本地尝试过,但您可以尝试使用this,通过将此属性组件添加到骆驼上下文中(也许您需要覆盖骆驼上下文配置)。然后你可以在 from 部分使用 {{file.uri}}。

PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:com/mycompany/myprop.properties");
context.addComponent("properties", pc);

【讨论】:

  • 感谢回复,因为我们有单点联系 application.properties,所以 this(PropertiesComponent) 将是应用程序的开销。
  • 对不起,你为什么不指向spring boot创建的application.properties呢?
  • 这是个好主意,直​​到我不知道哪个支持 .yml 或仅支持属性。谢谢,我会检查一下。
猜你喜欢
  • 2017-07-05
  • 2020-06-14
  • 1970-01-01
  • 2020-08-30
  • 2020-07-01
  • 2018-01-17
  • 1970-01-01
  • 2016-09-29
  • 2020-06-14
相关资源
最近更新 更多