定时获取微信access_token

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guanzhengyinqin/article/details/78499258

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添加上自己写的配置文件
这里写图片描述

猜你喜欢

转载自blog.csdn.net/guanzhengyinqin/article/details/78499258