2012-03-20 50 views
0

在骆驼上下文中定义的路由中,我想访问包含在第三方库I中的抽象类的方法I正在使用。访问驼峰上下文版本(2.9.1)中抽象类与Spring DSL的方法

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:camel="http://camel.apache.org/schema/spring" 
    xmlns:osgi="http://www.springframework.org/schema/osgi" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd 
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> 


<bean id="objectFactory" class="org.example.Factory" abstract="true"/> 

<camelContext xmlns="http://camel.apache.org/schema/spring"> 
    <route> 
     ... 
     <marshal> 
      <rss/> 
    </marshal> 
    <marshal> 
     <string/> 
    </marshal> 
     <to uri="jms:feeds"/> 
     <to uri="file:/tmp/output"/> 
     <!-- That is the point in the route where I would like to pass the URL of 
      the folder the files have been written to a static method of an abstract 
      class in order to instantiate an object 
     --> 
    </route> 
     ... 

上面的代码片断显示了Spring DSL中的路由定义和抽象bean的定义。我试过使用<bean>标签来达到我想要的效果,但这总是以org.springframework.beans.factory.BeanIsAbstractException结尾。有没有办法只是简单地访问camelcontext中的抽象类的静态方法?

回答

1

如果该方法是一个静态方法,你可以可以参考它在骆驼DSL直接

<bean type="org.example.Factory" method="myMethod"/> 

记住,这需要一个相当新的骆驼的版本,我们增加了对直接调用静态方法支持。

+0

感谢您的快速回答。我试图通过使用骆驼弹簧-DM原型:' <从URI ... /> <方法参照= “为helloBean” ... “/> <日志消息=” ... “/> ' 。这给了我一个'org.xml.sax.SAXParseException':'cvc-complex-type.3.2.2:属性'type'不允许出现在元素'bean'中。'我误解了它的设想要使用吗? – user1281204 2012-03-20 17:26:48

+0

是的里面有Camel命名空间,还有一个标签从路线中调用bean。 – 2012-03-21 08:01:49

1

我认为使用抽象类最简单的方法是定义自己的类,它扩展了抽象类,然后调用它。然后你可以使用正常的类似Claus的bean语法。在这种情况下,非静态方法也会起作用。

相关问题