@Service
アニメーション化されたクラスの@Async
メソッドは、非同期的に呼び出されていません。スレッドをブロックしています。Spring @Async Not Working
私の設定には<task: annotation-driven />
があり、メソッドの呼び出しはクラス外から来ているので、プロキシにヒットする必要があります。コードをステップ実行すると、プロキシは実際にヒットしますが、タスクエグゼキュータでの実行に関連するクラスの近くにはありません。
私はAsyncExecutionInterceptor
にブレークポイントを設定しましたが、決してヒットしません。私はAsyncAnnotationBeanPostProcessor
にデバッグし、アドバイスが適用されるのを見ることができます。
サービスは、@Async
というアノテーションが付けられた実装のメソッドで、(適切な対策のために、@Async
アノテーションを付けたメソッドで)インターフェイスとして定義されています。どちらも、@Transactional
と表示されていません。
何が間違っている可能性がありますか?
- = UPDATE = -
不思議なことに、それは私が私のアプリ-servlet.xmlファイルではなく、私のアプリ-services.xmlファイルで私のtask
XML要素を持っているのみときに動作し、私の場合私のコンポーネントはそこからサービスをスキャンします。通常、私はその中にコントローラだけを持つXMLファイルを持っています(それに応じてコンポーネントスキャンを制限します)。そしてもう一つはコンポーネントスキャンを制限して、他のXMLファイルを読み込みませんファイル)。
アプリ-servlet.xml
<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>
アプリ-services.xmlの(ここで指定したときに動作しません)
<?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 up Spring to scan through various packages to 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"/>
...
私は紛れも何かが足りません明らかに私の設定では、または設定要素間の微妙な相互作用が進行中ですか?
あなたは別のライブラリのものではなく、春の '@ ASync'タイプを使用していますか? – skaffman
'import org.springframework.scheduling.annotation.Async;'は私が使っているものです。私は、プロキシが呼び出されると、宣言されたクラス(インターフェイス)にクラスまたはメソッドレベルの注釈がないと思っています。これはうそです! –
ダブルチェックするだけで、メソッドはサービス内からではなく、外部から呼び出されていますか?そして、あなたは "新しい"エドアップしたサービスではなく、春から構築されたサービスのメソッドを呼び出していますか? – Pace