[英]How to add Camel properties component to camel context?
我目前正在嘗試將位置設置為我的屬性文件的屬性組件添加到我的項目中以使用屬性占位符:
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:properties.properties");
context.addComponent("properties", pc);
但是 addComponent() function 期望 Component 類型參數,而不是 PropertiesComponent,即使 PropertiesComponent 擴展了 DefaultComponent class。我已將此依賴項添加到 pom.xml 以使用它:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-properties</artifactId>
<version>3.0.0-M4</version>
</dependency>
並添加了資源標簽:
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
...
</build>
我得到的錯誤看起來像這樣:
java:不兼容的類型:org.apache.camel.component.properties.PropertiesComponent 無法轉換為 org.apache.camel.Component
我不知道是什么原因造成的,請幫忙。 謝謝。
PropertiesComponent
是一個非常特殊的組件,因此在 Camel 上下文中有專門的方法,如setPropertiesComponent
和getPropertiesComponent()
來管理它,您應該使用這些方法。
您的代碼應該類似於以下代碼:
// create the properties component
PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:properties.properties");
// add properties component to camel context
context.setPropertiesComponent(pc);
或者只是context.getPropertiesComponent().setLocation("classpath:properties.properties")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.