美文网首页
SpringBoot定时报Only no-arg methods

SpringBoot定时报Only no-arg methods

作者: 3d0829501918 | 来源:发表于2019-07-09 12:53 被阅读0次

  最近再用SpringBoot定时获取数据存入缓存,启动项目的时候发现出现如下错误:

 @Scheduled method 'getAllPhoneTasks': Only no-arg methods may be annotated with @Scheduled

 出现这个问题的原因是注解的方法上有参数,把参数去掉就行了。
注意:@Scheduled注解的方法要求不能有参数。

报错方法如下:

    @Scheduled(cron="0 0 0/4 * * ?")
    @PostMapping("/getAllPhoneTasks")
    public RespListJSON getAllPhoneTasks (TaskParam taskParam) {
        String areaId = taskParam.getAreaId();
        String key = SysConstants.PHONE_TASK + areaId;
        boolean falg = redisUtils.exists(key);
        List<CacheVO> allPhoneTasks;
        if (falg) {
            allPhoneTasks = (ArrayList<CacheVO>) redisUtils.get(key);
        } else {
            Map<String,String> map = new HashMap<>();
            map.put("areaId",areaId);
            allPhoneTasks = areaMacService.getAllPhoneTasks(map);
        }
        return new RespListJSON(allPhoneTasks);
    }

相关文章

网友评论

      本文标题:SpringBoot定时报Only no-arg methods

      本文链接:https://www.haomeiwen.com/subject/xjfxkctx.html