sun*_*leo 4 java apache-camel spring-boot
这可以在Apache Camel路由中使用Spring Boot属性吗?@Value工作正常但是这可以直接放置表达式的持有者.
更新:我知道PropertiesComponent,但除了Applicaiton.yml之外,还有一个我不喜欢的配置.
application.yml
sftp:
host: 10.10.128.128
user: ftpuser1
password: ftpuser1password
path: /tmp/inputfile/test1
Run Code Online (Sandbox Code Playgroud)
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?
Run Code Online (Sandbox Code Playgroud)
您可以在Camel中使用属性占位符(http://camel.apache.org/properties.html),如下所示:
from("sftp://{{sftp.user}}@{{sftp.host}}{{sftp.path}}?password={{sftp.password}}")
Run Code Online (Sandbox Code Playgroud)
您可以像这样注入完整链接,而不是将所有属性注入到单独的字段中:
@Value("#{'sftp://'+'${sftp.user}'+'@'+'${sftp.host}'+'${sftp.path}'+'?delete=true&password='+'${sftp.password}'}")
private String fullLink;
Run Code Online (Sandbox Code Playgroud)
然后,您可以在from方法中使用它。