[英]Spring Boot properties usage in Apache Camel route
這可以在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?
您可以在Camel中使用屬性占位符( http://camel.apache.org/properties.html ),如下所示:
from("sftp://{{sftp.user}}@{{sftp.host}}{{sftp.path}}?password={{sftp.password}}")
您可以注入完整的鏈接,而不是將所有屬性都注入到單獨的字段中:
@Value("#{'sftp://'+'${sftp.user}'+'@'+'${sftp.host}'+'${sftp.path}'+'?delete=true&password='+'${sftp.password}'}")
private String fullLink;
然后,您可以from
方法中使用它。
沒有在本地嘗試過,但你可以嘗試使用它 ,通過將這個屬性組件添加到camel上下文中(可能你需要覆蓋camel上下文配置)。 然后你可以在from部分中使用{{file.uri}}。
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:com/mycompany/myprop.properties");
context.addComponent("properties", pc);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.