3

25.5.3 元素

要同时启用@Scheduled 和@Async 注释,只需在配置中包含任务命名空间中的“注释驱动”元素。

<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>

<task:executor id="myExecutor" pool-size="5"/>

<task:scheduler id="myScheduler" pool-size="10"/>

请注意,提供了执行器引用来处理与带有@Async 注释的方法相对应的那些任务,并且提供了调度器引用来管理那些带有@Scheduled 注释的方法。

没有 XML 有没有办法做到这一点?

4

2 回答 2

10

这对于新发布的 Spring 3.1 是可能的,但不是 3.0 - 请参阅@EnableAsync@EnableScheduling.

于 2012-01-03T22:52:48.053 回答
1

对于@Dejel 问题:(因为我无法发表评论)

可以为某些任务指定执行者。这可以通过将执行程序名称指定为 @Async 注释的值来实现。看:

https://jira.spring.io/browse/SPR-6847

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/Async.html

http://www.baeldung.com/spring-async

于 2015-04-29T11:26:13.903 回答