Camel路由或端点配置中的Spring Boot属性



我是Camel的新手,正在边学习边学习。在一些框架(例如Spring Boot(和Camel之间似乎有很多可能的信息交换方式。我很难从Spring Boot属性中弄清楚如何(如果,甚至(做到这一点。我指的是CCD_ 1或CCD_。

下面的SO项目(ApacheCamel路由中的SpringBoot属性用法(提出了一个非常类似的问题,但答案似乎不起作用。我承认我真的不明白最后给出的答案。

那么我想做什么呢?由于我还是Camel的新手,我正在做一些非常基本和简单的事情。我有一个非常小的Spring Boot应用程序,它使用Camel简单地将文件从一个位置复制到另一个位置。

这是我的路线:

src/main/java/mypackage/CopyFileRoute.java:

@Component
public class CopyFileRoute extends RouteBuilder {
@Override
//@formatter:off
public void configure() throws Exception {
this
.from("file:{{properties.source-path}}/{{properties.file-name}}?noop=true")
.to("file:{{properties.dest-path}}/{{properties.file-name}}");
}
//@formatter:on
}

src/main/resources/application.yml:

properties:
source-path: demo/copyFrom
dest-path: demo/copyTo
file-name: test.txt

我在Camel用户指南中读到了属性替换(或占位符((https://camel.apache.org/manual/latest/using-propertyplaceholder.html和https://camel.apache.org/components/latest/properties-component.html),但无法使其发挥作用。当然,用户指南中的示例是XML配置,而我在Java配置中就是这样做的。这在Java代码中不起作用吗?

顺便说一句,我试图合并Camel属性"bridge"(BridgePropertyPlaceholderConfigurer(,但这也不起作用。我不确定我应该如何使用它。

更新

我用"桥"尝试了以下方法,但遗憾的是,这也不起作用:

@Configuration
@ComponentScan("mypackage")
public class Configurer {
@Bean
public CamelContext camelContext() {
return new DefaultCamelContext();
}
@Bean
public BridgePropertyPlaceholderConfigurer bridgePropertyPlaceholder() {
BridgePropertyPlaceholderConfigurer bridge = new BridgePropertyPlaceholderConfigurer();
bridge.setLocation(new ClassPathResource("application.properties"));
return bridge;
}
}

使用Java DSL可以实现

适用于Camel版本2.x.x

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addComponent("properties", new PropertiesComponent("file:C:\Your\path\application.properties"));
return context;
}

或适用于3.x.x 版本

@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
PropertiesComponent pc = context.getPropertiesComponent();
pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
return context;
}

最新更新