import org.springframework.scheduling.annotation.Scheduled;
@Component
public class TimedTask {
//@Scheduled(cron="0 0 12 * * ?")//每天12点跑
//@Scheduled(cron="0 0/5 * * * ?")//每5分钟 0 0 */1 * * ?
@Scheduled(cron=" 0 0 */1 * * ?")//每个小时跑一次
public void TaskJob(){
CommonUtil.token = CommonUtil.getToken(CommonUtil.APP_ID, CommonUtil.APP_SECRET);
System.out.println("当前access_token值------->"+CommonUtil.token.getAccessToken());
System.out.println("有效期---------->["+CommonUtil.token.getExpiresIn()+"]秒");
}
}
新建文件applicationContext-quartz.xml
在文件里写:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<!-- 开启定时任务 -->
<task:annotation-driven scheduler="qbScheduler" mode="proxy" />
<task:scheduler id="qbScheduler" pool-size="10"/>
</beans>
在web.xml添加上自己写的配置文件