2014-12-11 91 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