我正在尝试使用@Scheduled功能。我跟着this和this教程,但我无法让我的计划任务被执行。@预定任务不启动
我创建了一个工人:
@Component("syncWorker")
public class SyncedEliWorker implements Worker {
protected Logger logger = Logger.getLogger(this.getClass());
public void work() {
String threadName = Thread.currentThread().getName();
logger.debug(" " + threadName + " has began to do scheduled scrap with id=marketwatch2");
}
}
和SchedulingService:
@Service
public class SchedulingService {
protected Logger logger = Logger.getLogger(this.getClass());
@Autowired
@Qualifier("syncWorker")
private Worker worker;
@Scheduled(fixedDelay = 5000)
public void doSchedule() {
logger.debug("Start schedule");
worker.work();
logger.debug("End schedule");
}
}
而且在我的ApplicationContext尝试了不同的接线。 最终的版本是这样的:
<beans xmlns=...
xmlns:task="http://www.springframework.org/schema/task"
...
xsi:schemaLocation=" ..
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:annotation-config/>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>
<task:scheduler id="taskScheduler" pool-size="3"/>
<task:executor id="taskExecutor" pool-size="3"/>
... Other beans...
</beans>
的服务器出任何错误启动。
我错过了什么吗?