java - MDB with spring beans doesn't autowire beans from another package -
i using following mdb connect 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 {}
following spring beans being autowired part of interceptor annotation used in above mdb. event-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 package </beans>
following 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>
main 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>
i autowiring bean instances database & spring jms xmls in mdb package looks beans inside these xmls not created. can please understand can issue. autowire functionality of mdb restricted spring xmls in same package , other imports being done inside parent spring bean xml not created?
example: eventlistener
in com.abc.xyz
package. autowiring instance of class a
com.abc.core package in eventlistener class. class a
@service
, in turn has autowired dependency class b
in com.abc.packb
. when instance of class a
created exception saying no class b
definition found.
to solve problem need use springbeanautowiringsupport.
because mdb created not in spring context, must autowire beans need springbeanautowiringsupportprocessinjectionbasedoncurrentcontext(object target)
method or inherit mdb springbeanautowiringsupport
.
Comments
Post a Comment