2016-07-07 59 views
0

我正在建立OSGI捆綁在Jboss Fuse 6.1容器中運行。項目包含blueprint.xml(在src/main/resoureces/OSGI-INF/blueprint中)。它是內容:自動裝配彈簧豆在駱駝處理器

<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> 

我的目標是在MyProcessor中使用spring bean。這是代碼MyProcessor:

public class MyProcessor implements Processor { 

@Aurowired 
private Sender sender; 

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

}

但它帶給我的NullPointerException。我做錯了什麼?

這是我的Spring配置文件的內容(我把它的src/main/resoureces/META-INF /春)

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 
    <context:annotation-config/> 
    <context:component-scan base-package="com.username"/> 
<bean id="sender" class="com.username.Sender" scope="prototype"> 
    <property name="senderId" value="sendername" /> 
    <property name="password" value="senderpassword" /> 
</bean> 

+0

一般是有可能\t 同時採用彈簧豆藍圖豆?在我的例子中,藍圖創建駱駝路由和處理器,但春天創建自動裝配bean。 – Maciavelli

回答

0

我想你還沒有宣佈處理器MyProcessor爲在春天豆狀

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

,那麼你可以使用它作爲

<process ref="myProcessor"/> 

另外,

@Aurowired 
private Sender sender; 

應@Autowired(這應該是一個錯字,但指出了這一點。)

+0

是的,我在上面複製代碼時犯了一個錯誤。這個bean在藍圖中聲明。我已編輯。 – Maciavelli