如何让Quartz在启动时执行一次,以后按cron设置时间执行
5 回复
@IocBean
@Scheduled(cron = "0 */55 */1 * * ?") //每隔1小时55分钟执行一次
public class WxTokenJob implements Job {
private static final Logger log = LoggerFactory.getLogger(WxTokenJob.class);
@Inject
private DaoHelper daoHelper;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info("获取微信access_token");
try {
List<WxPublicNumber> list = daoHelper.getListByPOJO(WxPublicNumber.class, null);
for (WxPublicNumber wxPublicNumber : list) {
String url = HxdProperties.ACCESS_TOKEN;
Map<String, Object> params = new HashMap<>(2);
params.put("APPID", HxdProperties.HXD_APPID);
params.put("APPSECRET", HxdProperties.HXD_SECRET);
String strURL = SignUtil.formatUrl(url, params);
JSONObject json = HttpCallUtils.doHttpRequestForJson(strURL, "", "POST");
log.debug("获取微信access_token返回{}", json);
String token = json.getString("access_token");
getTicket(token,wxPublicNumber);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@wendal 请问怎么调用呢
WxTokenJob wxTokenJob = config.getIoc().get(WxTokenJob.class);
wxTokenJob.execute();
这样吗,但是里面要传一个JobExecutionContext
添加回复
请先登陆