2014-12-11 86 views
0

我已經經歷了大部分資源,並試圖通過以下機制將Spring Bean獲取到我的MDB。SpringBeanAutowiringInterceptor不向消息驅動Bean注入Spring Bean:空指針異常

@MessageDriven(name = "FileMDB") 
    @Interceptors(SpringBeanAutowiringInterceptor.class) 
    public class FileMessageBean implements MessageListener { 

     @Autowired 
     private IContextLoader contextLoader; 

     @Override 
     public final void onMessage(final Message message) { 

     } 
    } 

我的beanRefContext.xml位於JAR文件的類路徑中,它是WAR文件的依賴關係。

<?xml version="1.0" encoding="UTF-8"?> 
<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" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <bean 
     class="org.springframework.context.support.ClassPathXmlApplicationContext"> 
     <constructor-arg value="classpath:channel-integration-context.xml" /> 
    </bean> 

</beans> 

通道集成-context.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> 

    <!-- Activates various annotations to be detected in bean classes: Spring's 
     @Required and @Autowired, as well as JSR 250's @Resource. --> 
    <!-- <context:annotation-config /> --> 

    <!-- AOP Annotation -->  
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy> 

    <!-- File Adapter --> 
    <import resource="classpath:channel-dao-beans.xml" /> 

    <!-- JMS Beans --> 
    <import resource="classpath:jms-beans.xml" /> 

    <!-- Data JNDI Beans --> 
    <import resource="classpath:datasource-jndi-beans.xml" /> 

    <context:component-scan base-package="com.fdc.channelintegration" /> 

    <bean id="contextLoader" class="com.fdc.channelintegration.util.SpringContextLoader"> 
    </bean> 
</beans> 

我使用Websphere 8.5和我的MDB正確觸發。仍然contextLoader沒有注入到MDB,我得到一個NullPointerException。

請幫我一把。

回答

0
  1. 你沒忘了把@Cmponent@Service註釋您IContextLoader類,所以春天註釋處理器能找到它?
  2. <context:annotation-config />已被註釋掉。其返回到您的背景文件,並刪除從上下文文件中bean的@Interceptors(SpringBeanAutowiringInterceptor.class)
  3. 刪除defenition: <bean id="contextLoader" class="com.fdc.channelintegration.util.SpringContextLoader"/>
+0

謝謝你,小問題。爲什麼要移除SpringBeanAutowiringInterceptor?它假設將spring bean注入EJB的權利?有點困惑。 – 2014-12-11 06:44:06

+0

應該啓用註釋bean定義讀取器。看起來你正在使用默認(Singleton)範圍,所以自動裝配的依賴關係在上下文啓動時被注入。但是我可能會誤解它是否是一個EJB。 – Azee 2014-12-11 09:45:59