我正在尝试使用 @Scheduled 功能。我已按照此教程和本教程进行操作,但无法执行我的计划任务。
我创建了一个工人:
@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");
}
}
和一个调度服务:
@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");
}
}
并在我的应用程序上下文中尝试了不同的接线。最终版本如下所示:
<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>
服务器启动时没有任何错误。
我错过了什么吗?