2017-08-08 121 views
3

這可以在Apache Camel路由中使用Spring Boot屬性嗎? @Value工作正常,但可以直接放置表達式的持有者。Apache Camel路由中的Spring Boot屬性用法

更新:我知道PropertiesComponent,但除了我不喜歡的Applicaiton.yml之外,它將是一個更多的配置。

application.yml

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

春季啓動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? 
+0

你嘗試這樣做呢? – ByeBye

+0

是的,這是行不通的,它說空。它也不能綁定@ByeBye謝謝你的回覆 – sunleo

+0

你見過這個:http://camel.apache.org/properties.html –

回答

2

而是注入所有你的屬性來分隔字段,你可以注入這樣的完整鏈接:

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

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

+0

感謝您的回覆,這很有幫助。 – sunleo

1

沒有在本地嘗試過,但可以嘗試使用this,在駱駝上下文中添加此屬性組件(也許你需要重寫駱駝上下文配置)。然後你可以在from部件中使用{{file.uri}}。

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

感謝您的回覆,因爲我們有單點聯繫的application.properties,這個(PropertiesComponent)將是應用程序的開銷。 – sunleo

+0

對不起,你爲什麼不指向spring引導創建的application.properties? –

+0

這是個好主意,直​​到我不知道是否會支持.yml或只有properties.Thanks我會檢查這一點。 – sunleo