2016-11-09 52 views
1

有时我必须添加一个对象骆驼注册表(当然与Java)。在大多数情况下,它是一个数据源。骆驼如何添加注册表的东西 - 用java,一般

我的问题是我找不出一个一般的工作方式。

我总是开始获得注册表:

getContext().getRegistry(); 

但“注册表”没有任何方法来添加一个对象。所以,我必须尝试(使用调试器)在使用

getContext().getRegistry(some.class)<some method to add something>; 

例如,在一个项目(骆驼蓝图)什么样的注册表我要叫

SimpleRegistry registry = new SimpleRegistry(); 
registry.put("some", bean); 
getContext().getRegistry(CompositeRegistry.class).addRegistry(registry); 

现在,我创建了一个项目,同结构(也是相同的母版父),但现在上面的代码停止工作,因为由于某种原因,现在骆驼使用PropertyPlaceholderDelegateRegistry我相信会有代码来添加我的bean,但;

是否有代码可以与每个设置一起为骆驼注册表添加内容?

回答

4

这是一种将东西添加到RouteBuilder类的注册表中的方法。下面我添加一个TCPServerInitializerFactory,稍后会使用它。我总是使用camel-blueprint archetype,但是使用java dsl创建路线。这对我来说很好。

TCPServerInitializerFactory serverFactory = new TCPServerInitializerFactory(null); 
final CamelContext camelContext = getContext(); 
     final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry(); 
     final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry(); 
     compositeRegistry.addRegistry(camelContext.getRegistry()); 
     compositeRegistry.addRegistry(registry); 
     ((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry); 
    registry.put("spf", serverFactory); 
+0

不漂亮,但应该适用于所有情况 - 感谢 – dermoritz

+0

相信有一个整洁的方式,但我发现大多数方法是为纯Java的方法,而不是蓝图/ OSGi的一个和我一起工作。 –

+0

什么是纯java方法? – dermoritz