Spring Scheduler不起作用
问题内容:
我对基于Spring的基于注释的任务计划程序有问题-我无法使其正常运行,在这里我看不到任何问题…
application-context.xml
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler" />
豆
@Service
public final class SchedulingTest {
private static final Logger logger = Logger.getLogger(SchedulingTest.class);
@Scheduled(fixedRate = 1000)
public void test() {
logger.debug(">>> Scheduled test service <<<");
}
}
问题答案:
如果要使用task:annotation-driven
方法并且@Scheduled注释不起作用,则很可能context:component- scan
在上下文xml中丢失了。没有此行,spring无法猜测在哪里搜索注释。
<context:component-scan base-package="..." />