我正在使用以下 MDB 连接到 WMQ:
@MessageDriven(name = "EventListener", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "ABC"),
@ActivationConfigProperty(propertyName = "hostName", propertyValue = "ABC"),
@ActivationConfigProperty(propertyName = "port", propertyValue = "ABC"),
@ActivationConfigProperty(propertyName = "channel", propertyValue = "ABC"),
@ActivationConfigProperty(propertyName = "queueManager", propertyValue = "ABC"),
@ActivationConfigProperty(propertyName = "sslCipherSuite", propertyValue = "ABC"),
@ActivationConfigProperty(propertyName = "transportType", propertyValue = "CLIENT") })
@ResourceAdapter(value = "wmq.jmsra.rar")
@TransactionManagement(value = TransactionManagementType.CONTAINER)
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class EventListener implements MessageListener {}
以下 spring bean 将作为上述 MDB 中使用的拦截器注释的一部分进行自动装配。事件应用程序配置.xml:
<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:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.abc" />
<context:annotation-config/>
<import resource="classpath:core-app-config.xml" /> //This is another package
</beans>
以下是 core-app-config.xml:
<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:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
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
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd">
<import resource="classpath:database-config.xml" />
<import resource="classpath:spring-jms-config.xml" />
</beans>
主xml beanRefContext.xml:
<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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:spring-configured/>
<bean id="beanRefFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="classpath*:event-app-config.xml" />
</bean>
</beans>
我正在从 MDB 包中的数据库和 spring jms xmls 中自动装配某些 bean 实例,但看起来这些 xmls 中的所有 bean 都没有创建。你能理解可能是什么问题。MDB 的自动装配功能是否仅限于同一包中的 spring xml,并且未创建在父 spring bean xml 中进行的任何其他导入?
示例:EventListener
在com.abc.xyz
包装中。我A
在 eventlistener 类中从 com.abc.core 包中自动装配类的实例。类A
是@Service
,而那又具有自动装配的依赖关系,比如B
在com.abc.packB
. 所以当创建类的实例时,A
我得到一个异常,说没有B
找到类定义。