小编典典

Apache Camel路由中的Spring Boot属性用法

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

Spring Boot Apache骆驼路线:

 @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?

阅读 443

收藏
2020-05-30

共1个答案

小编典典

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

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

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

2020-05-30