Spring XML equivalent of @EnableAsync

2019-02-16 12:53发布

Is there a way to turn on Spring's Async configuration from XML? All the examples I saw are using programmatic context declaration and use @EnableAsync

Is there an XML equivalent for this. In some places I saw <context:annotation-config /> being used, but this doesn't mention anything about async .

I am using Spring 4.

2条回答
Fickle 薄情
2楼-- · 2019-02-16 13:16

Did you try using this

<task:annotation-driven /> 
查看更多
女痞
3楼-- · 2019-02-16 13:28

Yes, you can use something like this

 <beans>
     <task:annotation-driven executor="myExecutor" exception-handler="exceptionHandler"/>
     <task:executor id="myExecutor" pool-size="7-42" queue-capacity="11"/>
     <bean id="asyncBean" class="com.foo.MyAsyncBean"/>
     <bean id="exceptionHandler" class="com.foo.MyAsyncUncaughtExceptionHandler"/>
 </beans>

According to the Spring documentation, this is equivalent to using @EnableAsync

查看更多
登录 后发表回答