Spring XML相当于@EnableAsync

Mon*_*Sen 11 java spring asynchronous

有没有办法从XML打开Spring的Async配置?我看到的所有示例都使用程序化上下文声明和使用@EnableAsync

是否有XML等价物.在某些地方,我看到<context:annotation-config />被使用,但这没有提到任何关于异步的事情.

我正在使用Spring 4.

Pul*_*kit 10

你尝试过这个吗?

<task:annotation-driven /> 
Run Code Online (Sandbox Code Playgroud)


Mic*_*cho 5

是的,你可以使用这样的东西

 <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>
Run Code Online (Sandbox Code Playgroud)

根据Spring 文档,这相当于使用@EnableAsync