1

我正在使用以下 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 中进行的任何其他导入?

示例:EventListenercom.abc.xyz包装中。我A在 eventlistener 类中从 com.abc.core 包中自动装配类的实例。类A@Service,而那又具有自动装配的依赖关系,比如Bcom.abc.packB. 所以当创建类的实例时,A我得到一个异常,说没有B找到类定义。

4

1 回答 1

0

要解决这个问题,您需要使用SpringBeanAutowiringSupport

因为 MDB 不是在 Spring 上下文中创建的,所以您必须使用SpringBeanAutowiringSupportprocessInjectionBasedOnCurrentContext(Object target)方法自动装配所需的 bean 或从SpringBeanAutowiringSupport.

于 2016-01-25T06:50:49.717 回答