2

在骆驼上下文中定义的路由中,我想访问我正在使用的第 3 方库中包含的抽象类的方法。

 <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中抽象类的静态方法?

4

2 回答 2

1

我认为使用抽象类最简单的方法是定义自己的类来扩展抽象类,然后调用它。然后,您可以使用克劳斯提到的普通 bean 语法。在这种情况下,非静态方法也可以工作。

于 2012-03-21T06:51:45.233 回答
1

如果方法是静态方法,可以直接在 Camel DSL 中引用

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

请注意,这需要相当新的 Camel 版本,我们在其中添加了对直接调用静态方法的支持。

于 2012-03-20T16:57:48.103 回答