我已经浏览了大部分资源,并尝试使用以下机制将Spring Bean添加到我的MDB中。
@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>
channel-integration-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 :(得分:0)
@Cmponent
或@Service
注释,以便Spring注释处理器可以找到它?<context:annotation-config />
已被注释掉。将其返回到您的上下文文件并移除@Interceptors(SpringBeanAutowiringInterceptor.class)
<bean id="contextLoader" class="com.fdc.channelintegration.util.SpringContextLoader"/>