在骆驼处理器中自动装配spring bean

时间:2016-07-07 11:59:51

标签: spring apache-camel osgi jbossfuse blueprint-osgi

我正在构建OSGI包以便在Jboss Fuse 6.1容器中运行。项目包含blueprint.xml(在src / main / resoureces / OSGI-INF / blueprint中)。这是内容:

O(n logn)

我的目标是在MyProcessor中使用spring bean。这是MyProcessor的代码:

 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:camel="http://camel.apache.org/schema/blueprint"
               xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
               xmlns:cxf="http://cxf.apache.org/blueprint/core"
               xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"

               xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
           http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
            http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
     http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
    >
<bean id="MyProcessor" class="com.test.MyProcessor" />
          <camelContext trace="false" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
            <route>
                <from uri="activemq:queue:paymentsqueue?username=admin&amp;password=admin" id="NotificationRoute">
                    <description/>
                </from>
                <log message="The message contains ${body}"/>
                <process ref="MyProcessor"/>
            </route>
        </camelContext>
    </blueprint>

}

但它给了我nullpointerexception。我做错了什么?

这是我的spring配置文件的内容(我把它放在src / main / resoureces / META-INF / spring中)

public class MyProcessor implements Processor {

@Aurowired
private Sender sender;

@Override
public void process(Exchange x) throws Exception {
    log.info("test: " +sender.getSenderId());
}

1 个答案:

答案 0 :(得分:0)

我认为你没有像春天那样将处理器MyProcessor声明为一个bean

<bean id="myProcessor"
        class="com.test.MyProcessor" />

然后您可以将其用作

<process ref="myProcessor"/>

@Aurowired
private Sender sender;

应该是@Autowired(这应该是一个错字但指出来。)