Spring Boot properties usage in Apache Camel route

风流意气都作罢 提交于 2020-04-13 07:31:29

问题


Is this possible to use Spring Boot properties in Apache Camel route? @Value is working fine but is this possible to directly place in place holders of expressions.

Update: I know PropertiesComponent but which will be one more configuration apart from Applicaiton.yml that I don't like to have.

application.yml

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

Spring Boot Apache Camel Route:

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

回答1:


Instead of injecting all you properties to separate fields you can inject your full link like that:

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

Then, you can use it in from method.




回答2:


You can use property placeholders (http://camel.apache.org/properties.html) in Camel like this:

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



回答3:


Haven't tried it locally but you could try to use this, by adding this properties component into the camel context( maybe u need to override the camel context configuration). Then you could use {{file.uri}} inside the from parts.

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


来源:https://stackoverflow.com/questions/45567041/spring-boot-properties-usage-in-apache-camel-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!