spring添加定时器
1.spring的配置文件中添加
xmlns:task="http://www.springframework.org/schema/task"
然后xsi:schemaLocation加下面的内容、
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
<!-- task任务扫描注解 -->
<task:annotation-driven/>
<context:component-scan base-package="arch.pub.timer"></context:component-scan>
2。在arch.pub.timer包下新建class bean
@Service
public class LeaveTimer {
private static final Logger logger = LogManager.getLogger(LeaveTimer.class.getName());
@Scheduled(cron="0/5 * * * * ? ") //每5秒执行一次
public void run() throws Exception {
logger.error(UtilTime.getCurrentTime());
}
}
即可
浙公网安备 33010602011771号