我正在尝试重写以前使用spring上下文使用蓝图上下文和CamelBlueprintTestSupport
的单元测试。在不同的执行过程中,我看到了不同的错误,在尝试让它正常工作的过程中,我将camel-test-blueprint
更新为2.15.3
版本。现在,由于同样的错误,它总是失败:
java.lang.RuntimeException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext)
根本的问题是,不能解决属性占位符:
Caused by: java.lang.IllegalArgumentException: Property placeholder key: xyz not found
at org.apache.camel.blueprint.BlueprintPropertiesParser.parseProperty(BlueprintPropertiesParser.java:164) ~[camel-blueprint-2.15.3.jar:2.15.3]
我们在camel上下文和路由定义中使用蓝图属性占位符。我想这没什么特别的。
我试图创建一个简单的测试项目来重现问题,并且实际上设法在该测试项目中启动了上下文,但是对我的实际项目应用相同的步骤并不能解决问题。
在我的测试项目中,我有以下简单的设置:
blueprint.xml
<cm:property-placeholder id="appConfig" persistent-id="app" update-strategy="reload" />
<camelContext id="demoContext" xmlns="http://camel.apache.org/schema/blueprint" autoStartup="{{demo.sync}}" >
<route id="demoRoute" autoStartup="{{demo.route.startup}}">
<from uri="timer:test" />
<to uri="log:test" />
</route>
</camelContext>
测试类
public class RouteTest extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/blueprint.xml";
}
@Override
protected Properties useOverridePropertiesWithPropertiesComponent() {
Properties props = new Properties();
props.put("demo.sync", Boolean.TRUE.toString());
return props;
}
@Override
protected String[] loadConfigAdminConfigurationFile() {
URL cfg = this.getClass().getClassLoader().getResource("app.cfg");
return new String[] { cfg.getPath(), "app" };
}
我发现,如果不重写useOverridePropertiesWithPropertiesComponent
来返回camelContext
上的占位符,它将根本无法工作。通过重写loadConfigAdminConfigurationFile
,我让它加载实际的属性来替换第二个占位符。
我不确定我是否做错了什么,或者是否存在竞争状况,所以我想知道是否有人使用CamelBlueprintTestSupport
来获得蓝图属性占位符,并能给我一些提示吗?
发布于 2015-11-03 14:33:17
发布于 2015-11-04 00:48:21
我已经成功地使用了protected String useOverridePropertiesWithConfigAdmin(Dictionary props)
作为覆盖蓝图中属性的方法,您试过使用它吗?示例:
protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
props.put("demo.sync", true); //Add your properties in
return "app"; //return pid
}
https://stackoverflow.com/questions/33505848
复制