我使用以下MDB連接到WMQ自動裝配豆:MDB與彈簧豆不從另一個包
@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 {}
以下彈簧豆被自動裝配在上述MDB使用攔截器註釋的一部分。 事件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: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>
以下是核心應用-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>
我自動裝配來自數據庫&的某些bean實例在MDB包中彈出jms xmls,但看起來像這些xml中的所有bean都未創建。你能否理解可能是什麼問題。 是否將MDB的autowire功能限制在同一個包中的spring xml以及是否在父級spring bean xml內完成任何其他導入?
示例:EventListener
包含在com.abc.xyz
包中。我在eventlistener類的com.abc.core包中自動裝配類A
的實例。類A
是@Service
,並且依次具有自動佈線依賴關係,例如com.abc.packB
中的類B
。所以當創建類A
的實例時,我收到一個異常,說沒有找到類B
定義。
EventListener在哪個包中? – msknapp 2014-09-22 04:57:14
它在com.abc.xyz和core xml中,數據庫和彈簧都在com.abc.core – 2014-09-22 05:03:09
我沒有看到任何自動佈線材料(例如'@ Autowired'或'@Inject')。當使用'SpringBeanAutowiringInterceptor'時,需要一個名爲'beanRefContext.xml'的文件,它加載所有包含配置的xml文件。它不使用'ContextLoaderListener'。這在'SpringBeanAutowiringInterceptor'的[文檔](http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/ejb/interceptor/SpringBeanAutowiringInterceptor.html)中有解釋。 – 2014-09-22 05:36:33