骆驼读取属性文件

Jsm*_*ith 5 java spring apache-camel

如何使用 Java DSL 和 Main 对象配置属性文件的使用?

根据此页面,我应该可以调用以下内容:

main.setPropertyPlaceholderLocations("example.properties");
Run Code Online (Sandbox Code Playgroud)

然而,这根本行不通。似乎直到 Camel 2.18 才添加该选项,而我正在运行 2.17.1。

当让应用程序以独立形式运行时,设置要使用的属性文件的原始方法是什么?

一些背景故事:

我正在尝试从 Spring 转换为 Java DSL。在那次转换期间,我试图让我的 Camel 应用程序自行运行。我知道这是使用main.run();.

使用 CamelContext 时,我让事情“正常运行”,但不能单独运行。所以我知道在这种情况下使用以下方法会起作用:

PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:/myProperties.properties");
context.addComponent("properties", pc);
Run Code Online (Sandbox Code Playgroud)

有什么方法可以告诉我main使用该设置吗?或者还有什么需要吗?

Mil*_*vić 3

您可以使用以下代码片段:

PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:/myProperties.properties");
main.getCamelContexts().get(0).addComponent("properties", pc);
Run Code Online (Sandbox Code Playgroud)

另外,如果您正在使用camel-spring,则可以使用org.apache.camel.spring.Main类,它应该使用应用程序上下文中的属性占位符。