【发布时间】:2014-12-11 05:38:49
【问题描述】:
我已经浏览了大部分资源并尝试使用以下机制将 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。
请帮帮我。
【问题讨论】: