java - Spring @Async Not Working -



java - Spring @Async Not Working -

an @async method in @service-annotated class not beingness called asynchronously - it's blocking thread.

i've got <task: annotation-driven /> in config, , phone call method coming outside of class proxy should beingness hit. when step through code, proxy indeed hit, doesn't seem go anywhere near classes related running in task executor.

i've set breakpoints in asyncexecutioninterceptor , never hit. i've debugged asyncannotationbeanpostprocessor , can see advice getting applied.

the service defined interface (with method annotated @async there measure) implementation's method annotated @async too. neither marked @transactional.

any ideas may have gone wrong?

-=update=-

curiously, works only when have task xml elements in app-servlet.xml file, , not in app-services.xml file, , if component scanning on services there too. have 1 xml file controllers in (and restrict component-scan accordingly), , services in (again component-scan restricted such doesn't re-scan controllers loaded in other file).

app-servlet.xml

class="lang-xml prettyprint-override"><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:webflow="http://www.springframework.org/schema/webflow-config" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd" > <task:annotation-driven executor="executor" /> <task:executor id="executor" pool-size="7"/> <!-- enable controller annotations --> <context:component-scan base-package="com.package.store"> <!-- <context:include-filter type="annotation" expression="org.springframework.stereotype.controller" /> --> </context:component-scan> <tx:annotation-driven/> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory"/> </bean> <mvc:annotation-driven conversion-service="conversionservice" /> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/jsp/" /> <property name="suffix" value=".jsp" /> </bean>

app-services.xml (doesn't work when specified here)

class="lang-xml prettyprint-override"><?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" 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 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <!-- set spring scan through various packages find annotated classes --> <context:component-scan base-package="com.package.store"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.controller" /> </context:component-scan> <task:annotation-driven executor="han" /> <task:executor id="han" pool-size="6"/> ...

am missing glaringly obvious in configuration, or there subtle interplay between config elements going on?

with help of excellent reply ryan stewart, able figure out (at to the lowest degree specific problem).

in short, context loaded contextloaderlistener (generally applicationcontext.xml) parent of context loaded dispatcherservlet (generally *-servlet.xml). if have bean @async method declared/component-scanned in both contexts, version kid context (dispatcherservlet) override 1 in parent context (contextloaderlistener). verified excluding component component scanning in *-servlet.xml -- works expected.

java spring asynchronous

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -