[英]Spring Boot properties in Camel route or endpoint configuration
我是 Camel 的新手,并且正在学习。 似乎有很多可能的方法可以在某些框架(例如 Spring Boot)和 Camel 之间交换信息。 我很难弄清楚如何(甚至是否)从 Spring Boot 属性中做到这一点。 我的意思是application.properties
或application.yml
。
以下 SO 项目( Apache Camel 路由中的 Spring Boot 属性用法)提出了一个非常相似的问题,但答案似乎不起作用。 我承认我不太明白提供的最后一个答案。
那么我想做什么? 由于我还是 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 代码中不起作用吗?
顺便说一句,我试图合并骆驼属性“桥”( 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 你可以做到这一点
骆驼版本 2.xx
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addComponent("properties", new PropertiesComponent("file:C:\\Your\\path\\application.properties"));
return context;
}
或版本 3.xx
@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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.